import os
from io import StringIO
from chemsmart.settings.executable import (
CRESTExecutable,
GaussianExecutable,
ORCAExecutable,
XTBExecutable,
)
from chemsmart.settings.server import Server
from chemsmart.settings.submitters import PBSSubmitter, SLURMSubmitter
[docs]
class TestServer:
[docs]
def test_server_yaml(self, server_yaml_file):
assert os.path.exists(server_yaml_file)
assert os.path.isfile(server_yaml_file)
server = Server.from_yaml(name=server_yaml_file)
assert server.scheduler.lower() == "pbs"
assert server.queue_name == "normal"
assert server.num_hours == 24
assert server.mem_gb == 375
assert server.num_cores == 64
assert server.num_gpus == 0
assert server.num_threads == 64
assert server.submit_command == "qsub"
assert server.scratch_dir is None
assert server.use_hosts is True
assert (
server.extra_commands == """export PATH=$HOME/bin/chemsmart:$PATH
export PATH=$HOME/bin/chemsmart/chemsmart/cli:$PATH
export PATH=$HOME/bin/chemsmart/chemsmart/scripts:$PATH
export PYTHONPATH=$HOME/bin/chemsmart:$PYTHONPATH
"""
)
assert server.extra_scheduler_directives == "#PBS -m abe\n"
[docs]
def test_gaussian_executable(self, server_yaml_file):
gaussian_executable = GaussianExecutable.from_servername(
server_yaml_file
)
assert gaussian_executable.executable_folder == os.path.expanduser(
"~/programs/g16"
)
assert gaussian_executable.local_run is True
gaussian_conda_env = """source ~/anaconda3/etc/profile.d/conda.sh
conda activate ~/anaconda3/envs/chemsmart
"""
assert gaussian_executable.conda_env == gaussian_conda_env
gaussian_modules = """module purge
module load craype-x86-rome
module load libfabric/1.11.0.4.125
"""
assert gaussian_executable.modules == gaussian_modules
assert (
gaussian_executable.scripts
== 'tcsh -c "source ~/programs/g16/bsd/g16.login"\n'
)
gassian_envars = """export SCRATCH=~/scratch
export GAUSS_EXEDIR=~/programs/g16
export g16root=~/programs/g16
"""
assert gaussian_executable.envars == gassian_envars
[docs]
def test_orca_executable(self, server_yaml_file):
orca_executable = ORCAExecutable.from_servername(server_yaml_file)
assert orca_executable.executable_folder == os.path.expanduser(
"~/programs/orca_6_0_0"
)
assert orca_executable.local_run is False
assert orca_executable.conda_env is None
assert orca_executable.modules is None
assert orca_executable.scripts is None
orca_envars = """export PATH=~/programs/openmpi-4.1.6/build/bin:$PATH
export LD_LIBRARY_PATH=~/programs/openmpi-4.1.6/build/lib:$LD_LIBRARY_PATH
"""
assert orca_executable.envars == orca_envars
[docs]
def test_xtb_executable(self, server_yaml_file):
xtb_executable = XTBExecutable.from_servername(server_yaml_file)
assert xtb_executable.executable_folder is None
assert xtb_executable.get_executable() == "xtb"
assert xtb_executable.local_run is True
xtb_conda_env = """source ~/anaconda3/etc/profile.d/conda.sh
conda activate ~/anaconda3/envs/chemsmart
"""
assert xtb_executable.conda_env == xtb_conda_env
assert xtb_executable.modules is None
assert xtb_executable.scripts is None
assert xtb_executable.envars is None
[docs]
def test_crest_executable(self, server_yaml_file):
crest_executable = CRESTExecutable.from_servername(server_yaml_file)
assert crest_executable.executable_folder is None
assert crest_executable.get_executable() == "crest"
assert crest_executable.local_run is True
crest_conda_env = """source ~/anaconda3/etc/profile.d/conda.sh
conda activate ~/anaconda3/envs/chemsmart
"""
assert crest_executable.conda_env == crest_conda_env
assert crest_executable.modules is None
assert crest_executable.scripts is None
assert crest_executable.envars is None
[docs]
class TestMissingProgramSectionFallback:
"""Tests that Executable.from_servername raises ValueError when the
program block (e.g. XTB, CREST) is absent from the server YAML, and
that programs which ARE present still parse correctly.
Covers users who installed CHEMSMART before xTB support was added."""
[docs]
def test_xtb_missing_section_raises(self, legacy_server_yaml):
"""XTBExecutable.from_servername raises ValueError when XTB block absent."""
import pytest
with pytest.raises(ValueError, match="XTB"):
XTBExecutable.from_servername(legacy_server_yaml)
[docs]
def test_xtb_missing_section_error_message(self, legacy_server_yaml):
"""The ValueError message mentions updating the server YAML."""
import pytest
with pytest.raises(ValueError, match="server YAML"):
XTBExecutable.from_servername(legacy_server_yaml)
[docs]
def test_crest_missing_section_raises(self, legacy_server_yaml):
"""CRESTExecutable.from_servername raises ValueError when CREST block absent."""
import pytest
with pytest.raises(ValueError, match="CREST"):
CRESTExecutable.from_servername(legacy_server_yaml)
[docs]
def test_present_section_still_parsed_correctly(self, legacy_server_yaml):
"""Programs that *are* present in the legacy YAML are still parsed."""
exe = GaussianExecutable.from_servername(legacy_server_yaml)
assert exe.executable_folder == os.path.expanduser("~/programs/g16")
assert exe.local_run is True