Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aiida_amber/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
available in the PATH on almost any UNIX system.
"""

import os
import shutil
import tempfile

Expand Down Expand Up @@ -95,11 +96,14 @@ def get_code(entry_point, computer):
return codes[0]

path = get_path_to_executable(executable)
# AmberTools data files (e.g. dat/leap/parm/*) are looked up relative to AMBERHOME
amberhome = os.path.dirname(os.path.dirname(path))
code = InstalledCode(
label=executable,
default_calc_job_plugin=entry_point,
computer=computer,
filepath_executable=path,
prepend_text=f"export AMBERHOME={amberhome}",
)

return code.store()
28 changes: 23 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""pytest fixtures for simplified testing."""

import os
import shutil

import pytest

pytest_plugins = "aiida.tools.pytest_fixtures"
Expand All @@ -13,55 +16,70 @@ def clear_database_auto(aiida_profile_clean):
@pytest.fixture(scope="function")
def sander_code(aiida_code, aiida_localhost):
"""Get sander code."""
sander_path = shutil.which("sander")
amberhome = os.path.dirname(os.path.dirname(sander_path))
return aiida_code(
"core.code.installed",
label="amber",
computer=aiida_localhost,
filepath_executable="sander",
filepath_executable=sander_path,
prepend_text=f"export AMBERHOME={amberhome}",
)


@pytest.fixture(scope="function")
def tleap_code(aiida_code, aiida_localhost):
"""Get tleap code."""
tleap_path = shutil.which("tleap")
amberhome = os.path.dirname(os.path.dirname(tleap_path))
return aiida_code(
"core.code.installed",
label="amber",
computer=aiida_localhost,
filepath_executable="tleap",
filepath_executable=tleap_path,
prepend_text=f"export AMBERHOME={amberhome}",
)


@pytest.fixture(scope="function")
def antechamber_code(aiida_code, aiida_localhost):
"""Get antechamber code."""
antechamber_path = shutil.which("antechamber")
amberhome = os.path.dirname(os.path.dirname(antechamber_path))
return aiida_code(
"core.code.installed",
label="amber",
computer=aiida_localhost,
filepath_executable="antechamber",
filepath_executable=antechamber_path,
prepend_text=f"export AMBERHOME={amberhome}",
)


@pytest.fixture(scope="function")
def pdb4amber_code(aiida_code, aiida_localhost):
"""Get pdb4amber code."""
pdb4amber_path = shutil.which("pdb4amber")
amberhome = os.path.dirname(os.path.dirname(pdb4amber_path))
return aiida_code(
"core.code.installed",
label="amber",
computer=aiida_localhost,
filepath_executable="pdb4amber",
filepath_executable=pdb4amber_path,
prepend_text=f"export AMBERHOME={amberhome}",
)


@pytest.fixture(scope="function")
def parmed_code(aiida_code, aiida_localhost):
"""Get parmed code."""
parmed_path = shutil.which("parmed")
amberhome = os.path.dirname(os.path.dirname(parmed_path))
return aiida_code(
"core.code.installed",
label="amber",
computer=aiida_localhost,
filepath_executable="parmed",
filepath_executable=parmed_path,
prepend_text=f"export AMBERHOME={amberhome}",
)


Expand Down
35 changes: 35 additions & 0 deletions tests/cli/test_antechamber.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import subprocess

from aiida.orm.nodes.process.process import ProcessState
from click.testing import CliRunner

from aiida_amber.cli.antechamber import cli
from aiida_amber.utils import searchprevious

from .. import TEST_DIR
Expand All @@ -13,6 +15,7 @@
def test_launch_antechamber():
"""
Run an instance of antechamber.
Verify the actual installed console-script entry point (aiida_antechamber) works.
"""
# get input file paths
inp = os.path.join(TEST_DIR, "input_files", "antechamber", "LigA.mol2")
Expand Down Expand Up @@ -48,3 +51,35 @@ def test_launch_antechamber():
# check the process has finished and exited correctly
assert prev_calc.process_state == ProcessState.FINISHED
assert prev_calc.exit_status == 0


def test_cli_launch_antechamber(antechamber_code):
"""Invoke the antechamber cli in-process to cover cli/antechamber.py."""
inp = os.path.join(TEST_DIR, "input_files", "antechamber", "LigA.mol2")
result = CliRunner().invoke(
cli,
[
"-i",
inp,
"-o",
"LigandA.mol2",
"-fi",
"mol2",
"-fo",
"mol2",
"-c",
"bcc",
"-pf",
"yes",
"-nc",
"-2",
"-at",
"gaff2",
"-j",
"5",
"-rn",
"CHA",
],
catch_exceptions=False,
)
assert result.exit_code == 0
12 changes: 12 additions & 0 deletions tests/cli/test_parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import subprocess

from aiida.orm.nodes.process.process import ProcessState
from click.testing import CliRunner

from aiida_amber.cli.parmed import cli
from aiida_amber.utils import searchprevious

from .. import TEST_DIR
Expand All @@ -13,6 +15,7 @@
def test_launch_parmed():
"""
Run an instance of parmed.
Verify the actual installed console-script entry point (aiida_parmed) works.
"""
# get input file paths
parmed_in = os.path.join(TEST_DIR, "input_files", "parmed", "parmed_1264_na.in")
Expand All @@ -37,3 +40,12 @@ def test_launch_parmed():
# check the process has finished and exited correctly
assert prev_calc.process_state == ProcessState.FINISHED
assert prev_calc.exit_status == 0


def test_cli_launch_parmed(parmed_code):
"""Invoke the parmed cli in-process to cover cli/parmed.py."""
parmed_in = os.path.join(TEST_DIR, "input_files", "parmed", "parmed_1264_na.in")
prmtop = os.path.join(TEST_DIR, "input_files", "parmed", "1D23_tip4pew.prmtop")
inpcrd = os.path.join(TEST_DIR, "input_files", "parmed", "1D23_tip4pew.inpcrd")
result = CliRunner().invoke(cli, ["-i", parmed_in, "-p", prmtop, "-c", inpcrd], catch_exceptions=False)
assert result.exit_code == 0
18 changes: 17 additions & 1 deletion tests/cli/test_pdb4amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

from aiida_amber.utils import searchprevious

from click.testing import CliRunner
from aiida_amber.cli.pdb4amber import cli

from .. import TEST_DIR


def test_launch_pdb4amber():
"""
Run an instance of pdb4amber.
Verify the actual installed console-script entry point (aiida_pdb4amber) works.
"""
# get input file paths
inp = os.path.join(TEST_DIR, "input_files", "pdb4amber", "Protein.pdb")
Expand All @@ -35,4 +39,16 @@ def test_launch_pdb4amber():
prev_calc = qb.first()[0]
# check the process has finished and exited correctly
assert prev_calc.process_state == ProcessState.FINISHED
assert prev_calc.exit_status == 0
assert prev_calc.exit_status == 0


def test_cli_launch_pdb4amber(pdb4amber_code):
"""Invoke the pdb4amber cli in-process to cover cli/pdb4amber.py."""
inp = os.path.join(TEST_DIR, "input_files", "pdb4amber", "Protein.pdb")
result = CliRunner().invoke(
cli,
["-i", inp, "--out", "test.pdb", "--dry", "--reduce",
"--logfile", "test.log", "--leap-template"],
catch_exceptions=False,
)
assert result.exit_code == 0
16 changes: 16 additions & 0 deletions tests/cli/test_sander.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import subprocess

from aiida.orm.nodes.process.process import ProcessState
from click.testing import CliRunner

from aiida_amber.cli.sander import cli
from aiida_amber.utils import searchprevious

from .. import TEST_DIR
Expand All @@ -13,6 +15,7 @@
def test_launch_sander():
"""
Run an instance of sander.
Verify the actual installed console-script entry point (aiida_sander) works.
"""
# get input file paths
mdin = os.path.join(TEST_DIR, "input_files", "sander", "01_Min.in")
Expand Down Expand Up @@ -42,3 +45,16 @@ def test_launch_sander():
# check the process has finished and exited correctly
assert prev_calc.process_state == ProcessState.FINISHED
assert prev_calc.exit_status == 0


def test_cli_launch_sander(sander_code):
"""Invoke the sander cli in-process to cover cli/sander.py."""
mdin = os.path.join(TEST_DIR, "input_files", "sander", "01_Min.in")
prmtop = os.path.join(TEST_DIR, "input_files", "sander", "parm7")
inpcrd = os.path.join(TEST_DIR, "input_files", "sander", "rst7")
result = CliRunner().invoke(
cli,
["-i", mdin, "-p", prmtop, "-c", inpcrd, "-o", "01_Min.out", "-r", "01_Min.ncrst", "-inf", "01_Min.mdinfo"],
catch_exceptions=False,
)
assert result.exit_code == 0
10 changes: 10 additions & 0 deletions tests/cli/test_tleap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import subprocess

from aiida.orm.nodes.process.process import ProcessState
from click.testing import CliRunner

from aiida_amber.cli.tleap import cli
from aiida_amber.utils import searchprevious

from .. import TEST_DIR
Expand All @@ -13,6 +15,7 @@
def test_launch_tleap():
"""
Run an instance of tleap.
Verify the actual installed console-script entry point (aiida_tleap) works.
"""
# get input file paths
tleap_in = os.path.join(TEST_DIR, "input_files", "tleap", "tleap.in")
Expand All @@ -30,3 +33,10 @@ def test_launch_tleap():
# check the process has finished and exited correctly
assert prev_calc.process_state == ProcessState.FINISHED
assert prev_calc.exit_status == 0


def test_cli_launch_tleap(tleap_code):
"""Invoke the tleap cli in-process to cover cli/tleap.py."""
tleap_in = os.path.join(TEST_DIR, "input_files", "tleap", "tleap.in")
result = CliRunner().invoke(cli, ["-f", tleap_in], catch_exceptions=False)
assert result.exit_code == 0
Loading