From ea8e7bd34f79fef8fc53094fcc4dd6ed82b7e2ff Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:06:48 +0200 Subject: [PATCH] Delete openmmdl/tests/openmmdl_simulation directory --- .../cleaning_procedures_test.py | 187 --------------- .../forcefield_water_test.py | 223 ------------------ .../protein_ligand_prep_test.py | 173 -------------- .../test_post_md_conversions.py | 115 --------- 4 files changed, 698 deletions(-) delete mode 100644 openmmdl/tests/openmmdl_simulation/cleaning_procedures_test.py delete mode 100644 openmmdl/tests/openmmdl_simulation/forcefield_water_test.py delete mode 100644 openmmdl/tests/openmmdl_simulation/protein_ligand_prep_test.py delete mode 100644 openmmdl/tests/openmmdl_simulation/test_post_md_conversions.py diff --git a/openmmdl/tests/openmmdl_simulation/cleaning_procedures_test.py b/openmmdl/tests/openmmdl_simulation/cleaning_procedures_test.py deleted file mode 100644 index a3967ff3..00000000 --- a/openmmdl/tests/openmmdl_simulation/cleaning_procedures_test.py +++ /dev/null @@ -1,187 +0,0 @@ -import os -import shutil -import pytest -from pathlib import Path -from unittest.mock import mock_open, patch -from openmmdl.openmmdl_simulation.scripts.cleaning_procedures import ( - cleanup, - create_directory_if_not_exists, - post_md_file_movement, - copy_file, - create_directory_if_not_exists, - organize_files, -) - - -@pytest.fixture -def test_protein_name(): - return "test_protein" - - -@pytest.fixture -def test_directory_path(): - return "test_directory" - - -def test_cleanup(test_protein_name): - # Create a dummy file to be removed - with open(f"output_{test_protein_name}", "w") as dummy_file: - dummy_file.write("Dummy content") - - # Call the cleanup function - cleanup(test_protein_name) - - # Check if the file has been removed - assert not os.path.exists(f"output_{test_protein_name}") - - -def test_create_directory_if_not_exists(test_directory_path): - # Create a test directory - create_directory_if_not_exists(test_directory_path) - - # Check if the directory exists - assert os.path.exists(test_directory_path) - - # Call the function again, it should not raise an error - create_directory_if_not_exists(test_directory_path) - - # Cleanup: Remove the test directory - shutil.rmtree(test_directory_path) - assert not os.path.exists(test_directory_path) - - -@patch("os.path.exists") -@patch("shutil.copy") -def test_copy_file(mock_copy, mock_exists): - - src = "source_file.txt" - dest = "destination_directory" - - # Mock the os.path.exists to return True, indicating the source file exists - mock_exists.return_value = True - - # Call the copy_file function - copy_file(src, dest) - - # Check that os.path.exists was called with the source file - mock_exists.assert_called_with(src) - - # Check that shutil.copy was called with the source file and destination directory - mock_copy.assert_called_with(src, dest) - - -# Mock the os.path.exists and os.rename functions -@patch("os.path.exists") -@patch("os.rename") -def test_organize_files(mock_rename, mock_exists): - source = ["file1.txt", "file2.txt", "file3.txt"] - destination = "destination_directory" - - # Mock os.path.exists to return True for all source files - mock_exists.side_effect = [True] * len(source) - - # Call the organize_files function - organize_files(source, destination) - - # Print the calls made to os.rename - for call in mock_rename.call_args_list: - print(call) - - -# def test_post_md_file_movement(): -# # Get the absolute path to the test data directory -# test_data_directory = Path("openmmdl/tests/data/in") -# -# # Define the full path to the input files -# ligand = test_data_directory / 'CVV.sdf' -# protein_name = test_data_directory / '6b73.pdb' -# prmtop = test_data_directory / '6b73.prmtop' -# inpcrd = test_data_directory / '6b73.inpcrd' -# -# # Assert that the input files exist before moving -# assert os.path.exists(ligand) -# assert os.path.exists(protein_name) -# assert os.path.exists(prmtop) -# assert os.path.exists(inpcrd) -# -# # Call the post_md_file_movement function -# post_md_file_movement(protein_name, prmtop, inpcrd, ligand) -# -# # Check if the files have been organized and moved to the correct directories -# input_files_dir = Path("Input_Files") -# -# assert os.path.exists(input_files_dir) -# assert os.path.exists(input_files_dir / "6b73.pdb") -# assert os.path.exists(input_files_dir / "6b73.prmtop") -# assert os.path.exists(input_files_dir / "6b73.inpcrd") -# assert os.path.exists(input_files_dir / "CVV.sdf") - - -def test_post_md_file_movement(): - # Get the absolute path to the test data directory - test_data_directory = Path("openmmdl/tests/data/in") - - # Define the full path to the input files - ligand = test_data_directory / "CVV.sdf" - protein_name = test_data_directory / "6b73.pdb" - prmtop = test_data_directory / "6b73.prmtop" - inpcrd = test_data_directory / "6b73.inpcrd" - protein_no_solvent = test_data_directory / "prepared_no_solvent_6b73.pdb" - protein_solvent = test_data_directory / "solvent_padding_6b73.pdb" - protein_equilibration = test_data_directory / "Equilibration_6b73.pdb" - protein_minimization = test_data_directory / "Energyminimization_6b73.pdb" - output_pdb = test_data_directory / "output_6b73.pdb" - mdtraj_top = test_data_directory / "centered_old_coordinates_top.pdb" - prot_lig_top = test_data_directory / "prot_lig_top.pdb" - checkpoint = test_data_directory / "checkpoint.chk" - checkpoint_10x = test_data_directory / "10x_checkpoint.chk" - - # Assert that the input files exist before moving - assert os.path.exists(ligand) - assert os.path.exists(protein_name) - assert os.path.exists(prmtop) - assert os.path.exists(inpcrd) - assert os.path.exists(protein_no_solvent) - - shutil.copy(str(protein_no_solvent), ".") - shutil.copy(str(protein_solvent), ".") - shutil.copy(str(protein_equilibration), ".") - shutil.copy(str(protein_minimization), ".") - shutil.copy(str(output_pdb), ".") - shutil.copy(str(mdtraj_top), ".") - shutil.copy(str(prot_lig_top), ".") - shutil.copy(str(checkpoint), ".") - shutil.copy(str(checkpoint_10x), ".") - shutil.copy(str(protein_name), ".") - protein_name = "6b73.pdb" - - # Call the post_md_file_movement function - post_md_file_movement(str(protein_name), str(prmtop), str(inpcrd), [str(ligand)]) - - # Check if the files have been organized and moved to the correct directories - input_files_dir = Path("Input_Files") - md_files_dir = Path("MD_Files") - md_postprocessing_dir = Path("MD_Postprocessing") - final_output_dir = Path("Final_Output") - checkpoints_dir = Path("Checkpoints") - - assert os.path.exists(input_files_dir) - assert os.path.exists(md_files_dir / "Pre_MD") - assert os.path.exists(md_files_dir / "Pre_MD" / "prepared_no_solvent_6b73.pdb") - assert os.path.exists(md_files_dir / "Pre_MD" / "solvent_padding_6b73.pdb") - assert os.path.exists( - md_files_dir / "Minimization_Equilibration" / "Equilibration_6b73.pdb" - ) - assert os.path.exists( - md_files_dir / "Minimization_Equilibration" / "Energyminimization_6b73.pdb" - ) - assert os.path.exists(md_files_dir / "MD_Output" / "output_6b73.pdb") - assert os.path.exists(md_postprocessing_dir / "centered_old_coordinates_top.pdb") - assert os.path.exists(final_output_dir / "Prot_Lig" / "prot_lig_top.pdb") - assert os.path.exists(checkpoints_dir / "checkpoint.chk") - assert os.path.exists(checkpoints_dir / "10x_checkpoint.chk") - - -# Run the tests -if __name__ == "__main__": - pytest.main() diff --git a/openmmdl/tests/openmmdl_simulation/forcefield_water_test.py b/openmmdl/tests/openmmdl_simulation/forcefield_water_test.py deleted file mode 100644 index cd0967f9..00000000 --- a/openmmdl/tests/openmmdl_simulation/forcefield_water_test.py +++ /dev/null @@ -1,223 +0,0 @@ -import pytest -import simtk.openmm.app as app -from openff.toolkit.topology import Molecule -from openmmforcefields.generators import GAFFTemplateGenerator -from openmmdl.openmmdl_simulation.scripts.forcefield_water import ( - ff_selection, - water_forcefield_selection, - water_model_selection, - generate_forcefield, - generate_transitional_forcefield, -) - -# Replace 'your_module' with the actual name of the module containing your functions. - - -@pytest.fixture -def sample_rdkit_molecule(): - """ - A sample RDKit molecule for testing. - """ - from rdkit import Chem - - mol = Chem.MolFromSmiles("CCO") - return mol - - -def test_ff_selection(): - assert ff_selection("AMBER14") == "amber14-all.xml" - assert ff_selection("AMBER99SB") == "amber99sb.xml" - assert ff_selection("AMBER99SB-ILDN") == "amber99sbildn.xml" - assert ff_selection("AMBER03") == "amber03.xml" - assert ff_selection("AMBER10") == "amber10.xml" - assert ff_selection("CHARMM36") == "charmm36.xml" - assert ff_selection("NonexistentFF") is None - - -def test_water_forcefield_selection(): - # Test cases for 'amber14-all.xml' force field - assert water_forcefield_selection("TIP3P", "amber14-all.xml") == "amber14/tip3p.xml" - assert ( - water_forcefield_selection("TIP3P-FB", "amber14-all.xml") - == "amber14/tip3pfb.xml" - ) - assert water_forcefield_selection("SPC/E", "amber14-all.xml") == "amber14/spce.xml" - assert ( - water_forcefield_selection("TIP4P-Ew", "amber14-all.xml") - == "amber14/tip4pew.xml" - ) - assert ( - water_forcefield_selection("TIP4P-FB", "amber14-all.xml") - == "amber14/tip4pfb.xml" - ) - assert water_forcefield_selection("TIP5P", "amber14-all.xml") is None - assert water_forcefield_selection("NonexistentWater", "amber14-all.xml") is None - assert water_forcefield_selection("TIP3P", "NonexistentFF") is None - - # Test cases for 'charmm36.xml' force field - assert ( - water_forcefield_selection("CHARMM default", "charmm36.xml") - == "charmm36/water.xml" - ) - assert ( - water_forcefield_selection("TIP3P-PME-B", "charmm36.xml") - == "charmm36/tip3p-pme-b.xml" - ) - assert ( - water_forcefield_selection("TIP3P-PME-F", "charmm36.xml") - == "charmm36/tip3p-pme-f.xml" - ) - assert water_forcefield_selection("SPC/E", "charmm36.xml") == "charmm36/spce.xml" - assert ( - water_forcefield_selection("TIP4P-Ew", "charmm36.xml") == "charmm36/tip4pew.xml" - ) - assert ( - water_forcefield_selection("TIP4P-2005", "charmm36.xml") - == "charmm36/tip4p2005.xml" - ) - assert water_forcefield_selection("TIP5P", "charmm36.xml") == "charmm36/tip5p.xml" - assert ( - water_forcefield_selection("TIP5P-Ew", "charmm36.xml") == "charmm36/tip5pew.xml" - ) - assert water_forcefield_selection("NonexistentWater", "charmm36.xml") is None - assert water_forcefield_selection("NonexistentFF", "charmm36.xml") is None - - -def test_water_model_selection(): - assert water_model_selection("TIP3P", "amber99sb.xml") == "tip3p" - assert water_model_selection("TIP3P", "amber99sbildn.xml") == "tip3p" - assert water_model_selection("TIP3P", "amber03.xml") == "tip3p" - assert water_model_selection("TIP3P", "amber10.xml") == "tip3p" - - assert water_model_selection("SPC/E", "amber99sb.xml") == "spce" - assert water_model_selection("SPC/E", "amber99sbildn.xml") == "spce" - assert water_model_selection("SPC/E", "amber03.xml") == "spce" - assert water_model_selection("SPC/E", "amber10.xml") == "spce" - - assert water_model_selection("TIP4P-Ew", "amber99sb.xml") == "tip4pew" - assert water_model_selection("TIP4P-Ew", "amber99sbildn.xml") == "tip4pew" - assert water_model_selection("TIP4P-Ew", "amber03.xml") == "tip4pew" - assert water_model_selection("TIP4P-Ew", "amber10.xml") == "tip4pew" - - assert water_model_selection("TIP4P-FB", "amber99sb.xml") == "tip4pfb" - assert water_model_selection("TIP4P-FB", "amber99sbildn.xml") == "tip4pfb" - assert water_model_selection("TIP4P-FB", "amber03.xml") == "tip4pfb" - assert water_model_selection("TIP4P-FB", "amber10.xml") == "tip4pfb" - - assert water_model_selection("TIP5P", "amber99sb.xml") is None - assert water_model_selection("TIP5P", "amber99sbildn.xml") is None - assert water_model_selection("TIP5P", "amber03.xml") is None - assert water_model_selection("TIP5P", "amber10.xml") is None - assert ( - water_model_selection("TIP5P", "amber14-all.xml") is None - ) # Missing in the initial version - - assert water_model_selection("TIP3P", "amber14-all.xml") == "tip3p" - - assert water_model_selection("CHARMM default", "charmm36.xml") == "charmm" - assert water_model_selection("TIP3P-PME-B", "charmm36.xml") == "charmm" - assert water_model_selection("TIP3P-PME-F", "charmm36.xml") == "charmm" - assert water_model_selection("SPC/E", "charmm36.xml") == "charmm" - assert water_model_selection("TIP4P-Ew", "charmm36.xml") == "tip4pew" - assert water_model_selection("TIP4P-2005", "charmm36.xml") == "tip4pew" - assert water_model_selection("TIP5P", "charmm36.xml") == "tip5p" - assert water_model_selection("TIP5P-Ew", "charmm36.xml") == "tip5p" - - assert water_model_selection("TIP3P", "NonexistentFF") is None - - -def test_generate_forcefield_with_membrane(sample_rdkit_molecule): - forcefield = generate_forcefield( - "amber14-all.xml", "amber14/tip3p.xml", True, sample_rdkit_molecule - ) - assert isinstance(forcefield, app.ForceField) - # Add additional assertions specific to the case with a membrane - - -def test_generate_forcefield_without_membrane(sample_rdkit_molecule): - forcefield = generate_forcefield( - "amber14-all.xml", "amber14/tip3p.xml", False, sample_rdkit_molecule - ) - assert isinstance(forcefield, app.ForceField) - # Add additional assertions specific to the case without a membrane - - -def test_generate_forcefield_with_old_amber_forcefield(sample_rdkit_molecule): - forcefield = generate_forcefield( - "amber99sb.xml", "amber14/tip3p.xml", True, sample_rdkit_molecule - ) - assert isinstance(forcefield, app.ForceField) - # Add additional assertions specific to the case with an old Amber forcefield - - -def test_generate_forcefield_without_small_molecule(): - forcefield = generate_forcefield("amber14-all.xml", "amber14/tip3p.xml", False) - assert isinstance(forcefield, app.ForceField) - # Add additional assertions specific to the case without a small molecule - - -def test_generate_forcefield_membrane_logic(sample_rdkit_molecule): - forcefield_1 = generate_forcefield( - "amber10.xml", "tip3p.xml", True, sample_rdkit_molecule - ) - forcefield_2 = generate_forcefield( - "amber14-all.xml", "amber14/tip3p.xml", True, sample_rdkit_molecule - ) - forcefield_3 = generate_forcefield( - "amber14-all.xml", "amber14/tip3p.xml", False, sample_rdkit_molecule - ) - forcefield_4 = generate_forcefield( - "amber03.xml", "tip3p.xml", False, sample_rdkit_molecule - ) - - assert isinstance(forcefield_1, app.ForceField) - assert isinstance(forcefield_2, app.ForceField) - assert isinstance(forcefield_3, app.ForceField) - assert isinstance(forcefield_4, app.ForceField) - - # Additional tests for different force field combinations - forcefield_5 = generate_forcefield( - "amber14-all.xml", "tip3p.xml", True, sample_rdkit_molecule - ) - forcefield_6 = generate_forcefield( - "amber03.xml", "amber14/tip3p.xml", False, sample_rdkit_molecule - ) - - assert isinstance(forcefield_5, app.ForceField) - assert isinstance(forcefield_6, app.ForceField) - - # Additional tests for membrane flag logic - forcefield_7 = generate_forcefield( - "amber10.xml", "tip3p.xml", True, sample_rdkit_molecule - ) - forcefield_8 = generate_forcefield( - "amber14-all.xml", "tip3p.xml", False, sample_rdkit_molecule - ) - - assert isinstance(forcefield_7, app.ForceField) - assert isinstance(forcefield_8, app.ForceField) - - -def test_generate_transitional_forcefield(sample_rdkit_molecule): - transitional_forcefield = generate_transitional_forcefield( - "amber14-all.xml", "tip3p.xml", True, sample_rdkit_molecule - ) - assert isinstance(transitional_forcefield, app.ForceField) - - # Additional tests for different force field combinations - transitional_forcefield_2 = generate_transitional_forcefield( - "amber03.xml", "amber14/tip3p.xml", False, sample_rdkit_molecule - ) - assert isinstance(transitional_forcefield_2, app.ForceField) - - # Additional tests for membrane flag logic - transitional_forcefield_3 = generate_transitional_forcefield( - "amber14-all.xml", "tip3p.xml", False, sample_rdkit_molecule - ) - assert isinstance(transitional_forcefield_3, app.ForceField) - - # Additional tests for GAFF registration - transitional_forcefield_4 = generate_transitional_forcefield( - "amber14-all.xml", "tip3p.xml", True - ) - assert isinstance(transitional_forcefield_4, app.ForceField) diff --git a/openmmdl/tests/openmmdl_simulation/protein_ligand_prep_test.py b/openmmdl/tests/openmmdl_simulation/protein_ligand_prep_test.py deleted file mode 100644 index 78ae71f5..00000000 --- a/openmmdl/tests/openmmdl_simulation/protein_ligand_prep_test.py +++ /dev/null @@ -1,173 +0,0 @@ -import pytest -import os -import rdkit -from rdkit import Chem -import simtk.openmm.app as app -from simtk.openmm.app import PDBFile, Modeller -from simtk.openmm import unit -from simtk.openmm import Vec3 -import mdtraj as md -import numpy as np -import simtk -from pathlib import Path -import pdbfixer -from openmm.app import PDBFile -from pdbfixer import PDBFixer -import simtk.openmm.app as app - - -from simtk.openmm.app import ( - PDBFile, - Modeller, - PDBReporter, - StateDataReporter, - DCDReporter, - CheckpointReporter, -) -from simtk.openmm import unit, Platform, MonteCarloBarostat, LangevinMiddleIntegrator -from simtk.openmm import Vec3 -import simtk.openmm as mm - - -from openmmdl.openmmdl_simulation.scripts.forcefield_water import ( - ff_selection, - water_forcefield_selection, - water_model_selection, - generate_forcefield, - generate_transitional_forcefield, -) -from openmmdl.openmmdl_simulation.scripts.protein_ligand_prep import ( - prepare_ligand, - rdkit_to_openmm, - merge_protein_and_ligand, - water_padding_solvent_builder, - water_absolute_solvent_builder, - membrane_builder, - water_conversion, -) -from openmmdl.openmmdl_simulation.scripts.post_md_conversions import ( - mdtraj_conversion, - MDanalysis_conversion, -) - - -protein = "6b73.pdb" -ligand = "CVV.sdf" -ligand_name = "UNK" -minimization = False -sanitization = False -ff = "AMBER14" -water = "SPC/E" -add_membrane = False -Water_Box = "Buffer" -water_padding_distance = 1.0 -water_boxShape = "cube" -water_ionicstrength = 0.15 -water_positive_ion = "Na+" -water_negative_ion = "Cl-" - -water_box_x = 6.873 -water_box_y = 7.0 -water_box_z = 9.132 - -# Print current working directory -print("Current working directory:", os.getcwd()) - -# Assuming that 'test_data_directory' is properly defined in your test setup -test_data_directory = "openmmdl/tests/data/in" - - -test_data_directory = Path("openmmdl/tests/data/in") - - -# Define the full path to the input SDF file -TEST_LIGAND_FILE = f"{test_data_directory}/CVV.sdf" -TEST_MOL_FILE = f"{test_data_directory}/CVV.mol" -TEST_MOL2_FILE = f"{test_data_directory}/CVV.mol2" -TEST_PROTEIN = f"{test_data_directory}/6b73.pdb" - -protein_pdb = pdbfixer.PDBFixer(str(TEST_PROTEIN)) - - -ligand_prepared = prepare_ligand(TEST_LIGAND_FILE, minimize_molecule=minimization) -omm_ligand = rdkit_to_openmm(ligand_prepared, ligand_name) -forcefield_selected = ff_selection(ff) -water_selected = water_forcefield_selection( - water=water, forcefield_selection=ff_selection(ff) -) -model_water = water_model_selection(water=water, forcefield_selection=ff_selection(ff)) -forcefield = generate_forcefield( - protein_ff=forcefield_selected, - solvent_ff=water_selected, - add_membrane=add_membrane, - rdkit_mol=ligand_prepared, -) -complex_topology, complex_positions = merge_protein_and_ligand(protein_pdb, omm_ligand) -modeller = app.Modeller(complex_topology, complex_positions) - - -# Test the prepare_ligand function -def test_prepare_ligand(): - # Test the function with the sample ligand file. - rdkit_mol_sdf = prepare_ligand(TEST_LIGAND_FILE, minimize_molecule=False) - rdkit_mol_mol2_2 = prepare_ligand(TEST_MOL2_FILE, minimize_molecule=True) - rdkit_mol_mol = prepare_ligand(TEST_MOL_FILE, minimize_molecule=False) - rdkit_mol_mol2 = prepare_ligand(TEST_MOL2_FILE, minimize_molecule=False) - - # Add your assertions here to check if the preparation worked as expected - assert rdkit_mol_sdf is not None # Check if the result is not None - assert rdkit_mol_mol2_2 is not None # Check if the result is not None - assert rdkit_mol_mol is not None # Check if the result is not None - assert rdkit_mol_mol2 is not None # Check if the result is not None - - -def test_rdkit_to_openmm(): - omm_ligand = rdkit_to_openmm(ligand_prepared, ligand_name) - assert isinstance(omm_ligand, simtk.openmm.app.Modeller) - - -def test_merge_protein_and_ligand(): - complex_topology, complex_positions = merge_protein_and_ligand( - protein_pdb, omm_ligand - ) - assert complex_topology is not None - assert complex_positions is not None - - -def test_water_padding_solvent_builder(): - protein_buffer_solved = water_padding_solvent_builder( - model_water, - forcefield, - water_padding_distance, - protein_pdb, - modeller, - water_positive_ion, - water_negative_ion, - water_ionicstrength, - protein, - ) - assert protein_buffer_solved is not None - - -def test_water_absolute_solvent_builder(): - test_data_directory = Path("openmmdl/tests/data/in") - TEST_PROTEIN = f"{test_data_directory}/6b73.pdb" - protein_pdb = pdbfixer.PDBFixer(str(TEST_PROTEIN)) - protein_absolute_solved = water_absolute_solvent_builder( - model_water, - forcefield, - water_box_x, - water_box_y, - water_box_z, - protein_pdb, - modeller, - water_positive_ion, - water_negative_ion, - water_ionicstrength, - protein, - ) - assert protein_absolute_solved is not None - - -if __name__ == "__main__": - pytest.main() diff --git a/openmmdl/tests/openmmdl_simulation/test_post_md_conversions.py b/openmmdl/tests/openmmdl_simulation/test_post_md_conversions.py deleted file mode 100644 index 030f7304..00000000 --- a/openmmdl/tests/openmmdl_simulation/test_post_md_conversions.py +++ /dev/null @@ -1,115 +0,0 @@ -import pytest -import os -import shutil -from pathlib import Path -import mdtraj as md - -from openmmdl.openmmdl_simulation.scripts.post_md_conversions import ( - mdtraj_conversion, - MDanalysis_conversion, -) - -test_data_directory = Path("openmmdl/tests/data/in") -pdb_file = "0_unk_hoh.pdb" -dcd_file = "trajectory.dcd" -ligand_name = "UNK" - - -def test_mdtraj_conversion(): - original_cwd = os.getcwd() - os.chdir(test_data_directory) - # Create temporary directories to save the output files - output_file_dcd = "centered_old_coordinates.dcd" - output_file_xtc = "centered_old_coordinates.xtc" - output_file_pdb = "centered_old_coordinates_top.pdb" - output_file_gro = "centered_old_coordinates_top.gro" - - mdtraj_conversion(pdb_file, "gro_xtc") - mdtraj_conversion(pdb_file, "pdb_dcd") - - assert output_file_dcd is not None - assert output_file_xtc is not None - assert output_file_pdb is not None - assert output_file_gro is not None - os.chdir(original_cwd) - - -def test_mdanalysis_conversion(): - original_cwd = Path(os.getcwd()) - test_data_directory = Path("openmmdl/tests/data/in") - post_mdtraj_pdb_file = test_data_directory / "centered_old_coordinates_top.pdb" - post_mdtraj_dcd_file = test_data_directory / "centered_old_coordinates.dcd" - - # Create temporary directories to save the output files - all_file_dcd = "centered_traj.dcd" - all_file_dcd_unaligned = "centered_traj_unaligned.dcd" - all_file_pdb = "centered_top.pdb" - prot_lig_file_dcd = "prot_lig_traj.dcd" - prot_lig_file_dcd_unaligned = "prot_lig_traj_unaligned.dcd" - prot_lig_file_pdb = "prot_lig_top.pdb" - all_file_xtc = "centered_traj.xtc" - all_file_xtc_unaligned = "centered_traj_unaligned.xtc" - all_file_gro = "centered_top.gro" - prot_lig_file_xtc = "prot_lig_traj.xtc" - prot_lig_file_xtc_unaligned = "prot_lig_traj_unaligned.xtc" - prot_lig_file_gro = "prot_lig_top.gro" - - shutil.copy(str(post_mdtraj_pdb_file), ".") - shutil.copy(str(post_mdtraj_dcd_file), ".") - - post_mdtraj_pdb_file = "centered_old_coordinates_top.pdb" - post_mdtraj_dcd_file = "centered_old_coordinates.dcd" - ligand_name = "UNK" - mda_output = "pdb_dcd_gro_xtc" - output_selection = "mda_prot_lig_all" - - # MDanalysis_conversion(pdb_file, dcd_file, ligand_name, "pdb_dcd_gro_xtc", "mda_prot_lig_all") - MDanalysis_conversion( - post_mdtraj_pdb_file, - post_mdtraj_dcd_file, - mda_output, - output_selection, - ligand_name, - ) - - assert all_file_dcd is not None - assert all_file_dcd_unaligned is not None - assert all_file_pdb is not None - assert prot_lig_file_dcd is not None - assert prot_lig_file_dcd_unaligned is not None - assert prot_lig_file_pdb is not None - assert all_file_xtc is not None - assert all_file_xtc_unaligned is not None - assert all_file_gro is not None - assert prot_lig_file_xtc is not None - assert prot_lig_file_xtc_unaligned is not None - assert prot_lig_file_gro is not None - - # Assertions or checks to verify the correctness of the results - if "pdb" in mda_output: - if output_selection != "mda_all": - # Check if the expected PDB file exists - pdb_file_path = original_cwd / "prot_lig_top.pdb" - assert pdb_file_path.is_file() - - # Check if the expected DCD file exists - dcd_file_path = original_cwd / "prot_lig_traj.dcd" - assert dcd_file_path.is_file() - - # Check if the DCD file is not empty - traj = md.load(dcd_file_path, top=pdb_file_path) - assert traj.n_frames > 0 - - if "gro" in mda_output: - if output_selection != "mda_all": - # Check if the expected GRO file exists - gro_file_path = original_cwd / "prot_lig_top.gro" - assert gro_file_path.is_file() - - # Check if the expected XTC file exists - xtc_file_path = original_cwd / "prot_lig_traj.xtc" - assert xtc_file_path.is_file() - - # Check if the XTC file is not empty - traj = md.load(xtc_file_path, top=gro_file_path) - assert traj.n_frames > 0