Skip to content

Commit

Permalink
Merge pull request #29 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Added ability to run in containers.
  • Loading branch information
seamm authored Jan 16, 2024
2 parents 3b67f46 + 9048433 commit 9b6a2b2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
=======
History
=======

2024.1.16 -- Adding support for containers
* Added the ability to work in Docker containers.

2023.9.6 -- Using fractional coordinates for periodic systems.
* By convention, SEAMM is using fractional coordinates for periodic systems. The
PACKMOL step was creating periodic structures with Cartesian coordinates, which
Expand Down
3 changes: 3 additions & 0 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ dependencies:

# Pip-only installs
- pip:
# SEAMM
- seamm-exec

# Documentation
- sphinx-copybutton

Expand Down
64 changes: 28 additions & 36 deletions packmol_step/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

"""A step for building fluids with Packmol in a SEAMM flowchart"""

import configparser
import logging
import math
import os.path
from pathlib import Path
import pprint
import textwrap

Expand Down Expand Up @@ -69,14 +70,6 @@ def create_parser(self):
if parser_exists:
return result

# Options for Packmol
parser.add_argument(
self.step_type,
"--packmol-path",
default="",
help="the path to the Packmol executables",
)

return result

def description_text(self, P=None):
Expand Down Expand Up @@ -185,12 +178,8 @@ def run(self):
# Get the system database
system_db = self.get_variable("_system_db")

# The options from command line, config file ...
path = self.options["packmol_path"]

# and the executable
packmol_exe = os.path.join(path, "packmol")
seamm_util.check_executable(packmol_exe)
# Access the options
seamm_options = self.global_options

P = self.parameters.current_values_to_dict(
context=seamm.flowchart_variables._data
Expand Down Expand Up @@ -221,32 +210,35 @@ def run(self):

self.logger.log(0, pprint.pformat(files))

# Save the files to disk.
os.makedirs(self.directory, exist_ok=True)
for filename in files:
with open(os.path.join(self.directory, filename), mode="w") as fd:
fd.write(files[filename])
executor = self.flowchart.executor

# Read configuration file for MOPAC
ini_dir = Path(seamm_options["root"]).expanduser()
full_config = configparser.ConfigParser()
full_config.read(ini_dir / "packmol.ini")
executor_type = executor.name
if executor_type not in full_config:
raise RuntimeError(
f"No section for '{executor_type}' in PACKMOL ini file "
f"({ini_dir / 'packmol.ini'})"
)
config = dict(full_config.items(executor_type))

local = seamm.ExecLocal()
result = local.run(
cmd=(packmol_exe + " < input.inp"),
shell=True,
result = executor.run(
cmd=["{code}", "<", "input.inp", ">", "packmol.out"],
config=config,
directory=self.directory,
files=files,
return_files=["packmol.pdb"],
in_situ=True,
shell=True,
)

self.logger.debug(pprint.pformat(result))

# And write the output files out.
with open(os.path.join(self.directory, "packmol.out"), "w") as fd:
fd.write(result["stdout"])
if not result:
self.logger.error("There was an error running PACKMOL")
return None

for filename in result["files"]:
with open(os.path.join(self.directory, filename), mode="w") as fd:
if result[filename]["data"] is not None:
fd.write(result[filename]["data"])
else:
fd.write(result[filename]["exception"])
self.logger.debug(pprint.pformat(result))

# Get the bond orders and extra parameters like ff atom types
bond_orders = []
Expand All @@ -271,7 +263,7 @@ def run(self):
tmp_db.close()

# Get the system to fill and make sure it is empty
system, configuration = self.get_system_configuration(P)
system, configuration = self.get_system_configuration(P, same_as=None)
configuration.clear()
configuration.charge = total_q

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
seamm==2021.2.2
seamm
seamm_exec
tabulate
6 changes: 3 additions & 3 deletions tests/test_flowcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""Tests for `packmol_step` running full flowcharts."""
from pathlib import Path
import pytest
from seamm import run_flowchart
from seamm_exec import run

test_dir = Path(__file__).resolve().parent

Expand All @@ -30,7 +30,7 @@ def test_ideal_gas(monkeypatch, tmp_path, flowchart):
],
)

run_flowchart(wdir=str(tmp_path))
run(wdir=str(tmp_path))


@pytest.mark.unit
Expand All @@ -46,4 +46,4 @@ def test_unit(monkeypatch, tmp_path, flowchart):
],
)

run_flowchart(wdir=str(tmp_path))
run(wdir=str(tmp_path))

0 comments on commit 9b6a2b2

Please sign in to comment.