diff --git a/examples/ex02_h2_comparison.py b/examples/ex02_h2_comparison.py index a1c7081..864f88d 100644 --- a/examples/ex02_h2_comparison.py +++ b/examples/ex02_h2_comparison.py @@ -20,7 +20,7 @@ d = 0.9575 h2_root = Atoms("H2", positions=[(d, 0, 0), (0, 0, 0)], cell=[8, 8, 8], pbc=True) -rootdir = Path(__file__).parents[1] / "sandbox" +rootdir = Path(__file__).resolve().parents[1] / "sandbox" fmax = 0.005 ediff = 1e-7 diff --git a/examples/worker-cpu-spec.yml b/examples/worker-cpu-spec.yml index efbeaa0..b6e8d85 100644 --- a/examples/worker-cpu-spec.yml +++ b/examples/worker-cpu-spec.yml @@ -5,7 +5,7 @@ metadata: spec: restartPolicy: Never containers: - - image: ulissigroup/kubeflow_vasp:amptorch + - image: ulissigroup/kubeflow_vasp:beef_vdw imagePullPolicy: Always args: [dask-worker, --nthreads, '1', --no-dashboard, --memory-limit, 2GB, --death-timeout, '60'] name: dask @@ -13,7 +13,7 @@ spec: - name: PYTHONPATH value: "/home/jovyan/data/vasp-interactive-test:/home/jovyan/data/vasp-interactive-test/examples" - name: ASE_VASP_COMMAND - value: "mpirun -np 4 --mca btl_vader_single_copy_mechanism none /opt/vasp.6.1.2_pgi_mkl/bin/vasp_std" + value: "mpirun -np 4 --mca btl_vader_single_copy_mechanism none /opt/vasp.6.1.2_pgi_mkl/bin/vasp_gam" resources: limits: cpu: "4" diff --git a/setup.py b/setup.py index 2e305d9..fc53513 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="vasp-interactive", - version="0.0.1", + version="0.0.2", packages=["vasp_interactive", "vasp_interactive.kubernetes"], install_requires=[ "ase", diff --git a/tests/test_class.py b/tests/test_class.py index e67d65d..b7ccace 100644 --- a/tests/test_class.py +++ b/tests/test_class.py @@ -11,7 +11,7 @@ def test_class(): """Test if VaspInteractive correctly write inputs """ - atoms = molecule("C2H2", vacuum=5) + atoms = molecule("C2H2", vacuum=5, pbc=True) with tempfile.TemporaryDirectory() as tempdir: tempdir = Path(tempdir) calc = VaspInteractive(xc="pbe", directory=tempdir) @@ -56,7 +56,7 @@ def test_output(): """Test if VaspInteractive correctly write inputs """ - atoms = molecule("C2H2", vacuum=5) + atoms = molecule("C2H2", vacuum=5, pbc=True) with tempfile.TemporaryDirectory() as tempdir: # No value provided, default to vasp.out calc = VaspInteractive(xc="pbe", directory=tempdir) diff --git a/tests/test_command.py b/tests/test_command.py new file mode 100644 index 0000000..f3def38 --- /dev/null +++ b/tests/test_command.py @@ -0,0 +1,53 @@ +"""Testing if environmental variable correctly passes to process +""" +import pytest +from vasp_interactive import VaspInteractive +import tempfile +from pathlib import Path +import os +import sys + + +def test_command_env(): + from ase.build import molecule + + # When testing under the github action system, it should be + # `mpirun -np 1 /vasp_gam` + default_command = os.environ["VASP_COMMAND"] + + """Test if VaspInteractive correctly catches command if env changes + """ + atoms = molecule("H2", vacuum=5, pbc=True) + with tempfile.TemporaryDirectory() as tempdir: + tempdir = Path(tempdir) + calc = VaspInteractive(xc="pbe", directory=tempdir) + with calc: + atoms.calc = calc + assert calc.command is None + command = calc.make_command() + assert command == default_command + atoms.get_potential_energy() + # calc.process the shell mode, so args is a string + assert calc.process.args == default_command + + # Harmless change + new_command = default_command.replace("-np", "-n") + calc.command = new_command + # Should be no change + assert calc.process.args == default_command + + with calc: + atoms.rattle() + atoms.get_potential_energy() + print(calc.process.args) + assert calc.process.args == new_command + + with calc: + # reset the environ + os.environ["VASP_COMMAND"] = "echo TEST && " + default_command + atoms.rattle() + calc.command = None + atoms.get_potential_energy() + assert calc.command is None + print(calc.process.args) + assert "TEST" in calc.process.args diff --git a/vasp_interactive/vasp_interactive.py b/vasp_interactive/vasp_interactive.py index 9c0afc6..a9c0e86 100644 --- a/vasp_interactive/vasp_interactive.py +++ b/vasp_interactive/vasp_interactive.py @@ -86,12 +86,6 @@ def __init__( self.process = None self.allow_restart_process = allow_restart_process - # Make command a list of args for Popen - cmd = self.make_command(self.command) - if isinstance(cmd, str): - cmd = cmd.split() - self._args = cmd - # Ionic steps counter. Note this number will be 1 more than that in ase.optimize self.steps = 0 # Is the relaxation finished? @@ -196,7 +190,6 @@ def _stdin(self, text, out=None, ending="\n"): raise RuntimeError("VaspInteractive does not have the VASP process.") def _stdout(self, text, out=None): - """ """ if out is not None: out.write(text) @@ -240,9 +233,11 @@ def _run(self, atoms, out): self.initialize(atoms) self.write_input(atoms) self._stdout("Starting VASP for initial step...\n", out=out) - # Drop py2 support + # Dynamic generation of command args + command = self.make_command(self.command) self.process = Popen( - self._args, + command, + shell=True, stdout=PIPE, stdin=PIPE, stderr=PIPE,