Skip to content

Commit

Permalink
Merge pull request #26 from bigd4/disable_printing
Browse files Browse the repository at this point in the history
Not show c++ infomation
  • Loading branch information
bigd4 authored Jun 1, 2024
2 parents fbbde31 + e7df316 commit 75dcffe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions nep_cpu/src/pynep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/iostream.h>
namespace py = pybind11;

struct Atom {
Expand Down Expand Up @@ -37,6 +38,10 @@ class NepCalculator
NepCalculator::NepCalculator(std::string _model_file)
{
model_file = _model_file;
py::scoped_ostream_redirect stream(
std::cout, // std::ostream&
py::module_::import("sys").attr("stdout") // Python output
);
calc = NEP3(model_file);
info["version"] = calc.paramb.version;
info["zbl"] = calc.zbl.enabled;
Expand Down
5 changes: 4 additions & 1 deletion pynep/calculate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import os, contextlib
from ase.calculators.calculator import (
Calculator,
all_changes,
Expand Down Expand Up @@ -48,7 +49,9 @@ def __init__(self, model_file="nep.txt", **kwargs) -> None:
model_file (str, optional): filename of nep model. Defaults to "nep.txt".
"""
Calculator.__init__(self, **kwargs)
self.calc = NepCalculator(model_file)
with open(os.devnull, 'w') as devnull:
with contextlib.redirect_stdout(devnull), contextlib.redirect_stderr(devnull):
self.calc = NepCalculator(model_file)
self.type_dict = {e: i for i, e in enumerate(self.calc.info["element_list"])}

def __repr__(self):
Expand Down

0 comments on commit 75dcffe

Please sign in to comment.