From 3f9e852931675eabddbc4bb56a71f9b1be63692c Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Mon, 9 Dec 2024 12:17:06 +0000 Subject: [PATCH] Add test to validate correct update of triclinic box vectors. [ref OpenBioSim/sire#265] --- tests/Process/test_somd.py | 47 +++++++++++++++++- tests/Sandpit/Exscientia/Process/test_somd.py | 49 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/tests/Process/test_somd.py b/tests/Process/test_somd.py index 0f077ca17..3a8ca112b 100644 --- a/tests/Process/test_somd.py +++ b/tests/Process/test_somd.py @@ -129,11 +129,56 @@ def test_pert_res_num(perturbable_system): assert unique1[0] == "perturbed residue number = 2" +def test_triclinic(): + """ + Test the triclinic box vectors can be updated correctly with OpenMM 8.2+. + """ + + # Load the triclinic alanine dipeptide system. + system = BSS.IO.readMolecules( + BSS.IO.expand(url, ["ala_triclinic.rst7", "ala_triclinic.prm7"]) + ) + + # Create a short production protocol. + protocol = BSS.Protocol.Production(runtime=BSS.Types.Time(0.001, "nanoseconds")) + + # Run the process, check that it finished without error, and returns a system. + run_process(system, protocol) + + +def test_triclinic_fep(): + """ + Test the triclinic box vectors can be updated correctly with OpenMM 8.2+. + """ + + # Load the triclinic alanine dipeptide system. + system = BSS.IO.readPerturbableSystem( + *BSS.IO.expand( + url, + [ + "ethane_methanol_triclinic0.prm7", + "ethane_methanol_triclinic0.rst7", + "ethane_methanol_triclinic1.prm7", + "ethane_methanol_triclinic1.rst7", + ], + ) + ) + + # Create a short production FEP protocol. + protocol = BSS.Protocol.FreeEnergy(runtime=0.1 * BSS.Units.Time.picosecond) + + # Run the process, check that it finished without error, and returns a system. + run_process(system, protocol) + + def run_process(system, protocol): """Helper function to run various simulation protocols.""" + # Use CUDA platform is CUDA_VISIBLE_DEVICES is set. + platform = "CUDA" if "CUDA_VISIBLE_DEVICES" in os.environ else "CPU" + # Initialise the SOMD process. - process = BSS.Process.Somd(system, protocol, name="test", platform="CPU") + process = BSS.Process.Somd(system, protocol, name="test", platform=platform) # Start the SOMD simulation. process.start() diff --git a/tests/Sandpit/Exscientia/Process/test_somd.py b/tests/Sandpit/Exscientia/Process/test_somd.py index 9147ee3d0..c205ea421 100644 --- a/tests/Sandpit/Exscientia/Process/test_somd.py +++ b/tests/Sandpit/Exscientia/Process/test_somd.py @@ -269,11 +269,58 @@ def test_restraint_mdr(tmp_path, restraint_mdr): assert "permanent distance restraints dictionary" in lines[-1] +def test_triclinic(): + """ + Test the triclinic box vectors can be updated correctly with OpenMM 8.2+. + """ + + # Load the triclinic alanine dipeptide system. + system = BSS.IO.readMolecules( + BSS.IO.expand(url, ["ala_triclinic.rst7", "ala_triclinic.prm7"]) + ) + + # Create a short production protocol. + protocol = BSS.Protocol.Production(runtime=BSS.Types.Time(0.001, "nanoseconds")) + + # Run the process, check that it finished without error, and returns a system. + run_process(system, protocol) + + +def test_triclinic_fep(): + """ + Test the triclinic box vectors can be updated correctly with OpenMM 8.2+. + """ + + # Load the triclinic alanine dipeptide system. + system = BSS.IO.readPerturbableSystem( + *BSS.IO.expand( + url, + [ + "ethane_methanol_triclinic0.prm7", + "ethane_methanol_triclinic0.rst7", + "ethane_methanol_triclinic1.prm7", + "ethane_methanol_triclinic1.rst7", + ], + ) + ) + + # Create a short production FEP protocol. + protocol = BSS.Protocol.FreeEnergy(runtime=0.1 * BSS.Units.Time.picosecond) + + # Run the process, check that it finished without error, and returns a system. + run_process(system, protocol) + + def run_process(system, protocol, **kwargs): """Helper function to run various simulation protocols.""" + # Use CUDA platform is CUDA_VISIBLE_DEVICES is set. + platform = "CUDA" if "CUDA_VISIBLE_DEVICES" in os.environ else "CPU" + # Initialise the SOMD process. - process = BSS.Process.Somd(system, protocol, name="test", platform="CPU", **kwargs) + process = BSS.Process.Somd( + system, protocol, name="test", platform=platform, **kwargs + ) # Start the SOMD simulation. process.start()