Skip to content

Commit 75dcffe

Browse files
authored
Merge pull request #26 from bigd4/disable_printing
Not show c++ infomation
2 parents fbbde31 + e7df316 commit 75dcffe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

nep_cpu/src/pynep.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <pybind11/pybind11.h>
99
#include <pybind11/stl.h>
10+
#include <pybind11/iostream.h>
1011
namespace py = pybind11;
1112

1213
struct Atom {
@@ -37,6 +38,10 @@ class NepCalculator
3738
NepCalculator::NepCalculator(std::string _model_file)
3839
{
3940
model_file = _model_file;
41+
py::scoped_ostream_redirect stream(
42+
std::cout, // std::ostream&
43+
py::module_::import("sys").attr("stdout") // Python output
44+
);
4045
calc = NEP3(model_file);
4146
info["version"] = calc.paramb.version;
4247
info["zbl"] = calc.zbl.enabled;

pynep/calculate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import os, contextlib
23
from ase.calculators.calculator import (
34
Calculator,
45
all_changes,
@@ -48,7 +49,9 @@ def __init__(self, model_file="nep.txt", **kwargs) -> None:
4849
model_file (str, optional): filename of nep model. Defaults to "nep.txt".
4950
"""
5051
Calculator.__init__(self, **kwargs)
51-
self.calc = NepCalculator(model_file)
52+
with open(os.devnull, 'w') as devnull:
53+
with contextlib.redirect_stdout(devnull), contextlib.redirect_stderr(devnull):
54+
self.calc = NepCalculator(model_file)
5255
self.type_dict = {e: i for i, e in enumerate(self.calc.info["element_list"])}
5356

5457
def __repr__(self):

0 commit comments

Comments
 (0)