From e5bbaf3f111576b629c31472967974de89cc0137 Mon Sep 17 00:00:00 2001 From: Diego Prada Date: Tue, 17 Oct 2023 16:45:12 -0600 Subject: [PATCH] in process --- .github/workflows/CI.yaml | 2 +- .../_private/digestion/argument/selection.py | 4 + molsysmt/structure/flip.py | 3 + molsysmt/structure/least_rmsd_align.py | 59 +++++---- .../basic/get/test_get_molsysmt_MolSys.py | 64 +--------- molsysmt/tests/basic/test_is_composed_of.py | 2 +- .../align/test_align_molsysmt_MolSys.py | 2 +- .../fit/test_fit_from_molsysmt_MolSys.py | 2 +- sandbox/Test.ipynb | 116 ++++++++++++------ 9 files changed, 120 insertions(+), 134 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index c938d06b1..6871db4b2 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -87,7 +87,7 @@ jobs: shell: bash -l {0} run: | - pytest -v --cov=molsysmt --cov-report=xml --color=yes molsysmt/tests/ + pytest -n auto -v --cov=molsysmt --cov-report=xml --color=yes molsysmt/tests/ - name: CodeCov uses: codecov/codecov-action@v1 diff --git a/molsysmt/_private/digestion/argument/selection.py b/molsysmt/_private/digestion/argument/selection.py index 8d0619085..518fcf326 100644 --- a/molsysmt/_private/digestion/argument/selection.py +++ b/molsysmt/_private/digestion/argument/selection.py @@ -34,6 +34,8 @@ def digest_selection(selection, syntax="MolSysMT", caller=None): return list(selection) else: return list([digest_selection(ii, syntax=syntax, caller=caller) for ii in selection]) + elif isinstance(selection, range): + return list(selection) elif selection is None: return None else: @@ -43,6 +45,8 @@ def digest_selection(selection, syntax="MolSysMT", caller=None): return np.array([selection], dtype='int64') elif isinstance(selection, (np.ndarray, list, tuple, range)): return np.array(selection, dtype='int64') + elif isinstance(selection, range): + return list(selection) elif selection is None: return None diff --git a/molsysmt/structure/flip.py b/molsysmt/structure/flip.py index fd885866a..d34598e7f 100644 --- a/molsysmt/structure/flip.py +++ b/molsysmt/structure/flip.py @@ -20,10 +20,13 @@ def flip(molecular_system, vector=[0,0,1], point='[0,0,0] nm', selection='all', coordinates, length_unit = puw.get_value_and_unit(coordinates) point = puw.get_value(point, to_unit=length_unit) + point = point[0] + coordinates = msmlib.structure.flip(coordinates, vector, point) coordinates = puw.quantity(coordinates, unit=length_unit) + if in_place: set(molecular_system, selection=selection, structure_indices=structure_indices, diff --git a/molsysmt/structure/least_rmsd_align.py b/molsysmt/structure/least_rmsd_align.py index dca38e183..2ab66b61c 100644 --- a/molsysmt/structure/least_rmsd_align.py +++ b/molsysmt/structure/least_rmsd_align.py @@ -6,7 +6,7 @@ @digest() def least_rmsd_align(molecular_system, selection='atom_name=="CA"', structure_indices='all', reference_molecular_system=None, reference_selection=None, reference_structure_indices=0, - syntax='MolSysMT', method='sequence alignment and least rmsd fit', + syntax='MolSysMT', engine_sequence_alignment = 'Biopython', engine_least_rmsd_fit = 'MolSysMT'): """ To be written soon... @@ -17,47 +17,46 @@ def least_rmsd_align(molecular_system, selection='atom_name=="CA"', structure_in if reference_selection is None: reference_selection = selection - if method == 'sequence alignment and least rmsd fit': + from molsysmt.basic import select - from molsysmt.basic import select + if engine_sequence_alignment == 'Biopython': - if engine_sequence_alignment == 'Biopython': + from molsysmt.topology import get_sequence_identity - from molsysmt.topology import get_sequence_identity + identity, identical_groups, reference_identical_groups = get_sequence_identity(molecular_system, + selection=selection, reference_molecular_system=reference_molecular_system, reference_selection=reference_selection, + engine='Biopython') - identity, identical_groups, reference_identical_groups = get_sequence_identity(molecular_system, - selection=selection, reference_molecular_system=reference_molecular_system, reference_selection=reference_selection, - engine='Biopython') - - else: + else: - raise NotImplementedMethodError + raise NotImplementedMethodError - aux_atoms_list = select(molecular_system, element='atom', - selection='group_index==@identical_groups') - selection_to_be_fitted = select(molecular_system, element='atom', selection=selection, - mask=aux_atoms_list) - components_selected = select(molecular_system, element='component', selection=selection) - atoms_in_components_selected = select(molecular_system, element='atom', selection='component_index==@components_selected') + aux_atoms_list = select(molecular_system, element='atom', + selection='group_index==@identical_groups') + selection_to_be_fitted = select(molecular_system, element='atom', selection=selection, + mask=aux_atoms_list) + components_selected = select(molecular_system, element='component', selection=selection) + atoms_in_components_selected = select(molecular_system, element='atom', selection='component_index==@components_selected') - aux_atoms_list = select(reference_molecular_system, element='atom', selection='group_index==@reference_identical_groups') - reference_selection_to_be_fitted = select(reference_molecular_system, element='atom', - selection=reference_selection, mask=aux_atoms_list) + aux_atoms_list = select(reference_molecular_system, element='atom', selection='group_index==@reference_identical_groups') + reference_selection_to_be_fitted = select(reference_molecular_system, element='atom', + selection=reference_selection, mask=aux_atoms_list) - del(aux_atoms_list, components_selected) - del(identity, identical_groups, reference_identical_groups) + del(aux_atoms_list, components_selected) + del(identity, identical_groups, reference_identical_groups) - if engine_least_rmsd_fit == 'MolSysMT': + if engine_least_rmsd_fit == 'MolSysMT': - from molsysmt.structure import fit + from molsysmt.structure import least_rmsd_fit - output = fit(molecular_system=molecular_system, selection=atoms_in_components_selected, selection_fit=selection_to_be_fitted, - structure_indices=structure_indices, reference_molecular_system=reference_molecular_system, - reference_selection_fit=reference_selection_to_be_fitted, reference_structure_indices=reference_structure_indices, - to_form=None, in_place=False, engine='MolSysMT', syntax=syntax) + output = least_rmsd_fit(molecular_system=molecular_system, selection=atoms_in_components_selected, + selection_fit=selection_to_be_fitted, + structure_indices=structure_indices, reference_molecular_system=reference_molecular_system, + reference_selection_fit=reference_selection_to_be_fitted, reference_structure_indices=reference_structure_indices, + to_form=None, in_place=False, engine='MolSysMT', syntax=syntax) - del(atoms_in_components_selected, selection_to_be_fitted, reference_selection_to_be_fitted) - del(structure_indices, reference_structure_indices) + del(atoms_in_components_selected, selection_to_be_fitted, reference_selection_to_be_fitted) + del(structure_indices, reference_structure_indices) else: diff --git a/molsysmt/tests/basic/get/test_get_molsysmt_MolSys.py b/molsysmt/tests/basic/get/test_get_molsysmt_MolSys.py index 4a66e9dc1..be477f6be 100644 --- a/molsysmt/tests/basic/get/test_get_molsysmt_MolSys.py +++ b/molsysmt/tests/basic/get/test_get_molsysmt_MolSys.py @@ -7,17 +7,16 @@ from molsysmt.systems import tests as tests_systems import numpy as np - # Get on molsysmt.MolSys +molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') + def test_get_1(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') output = msm.get(molsys, element='atom', selection=[32, 33, 34], name=True) true_output = np.array(['N', 'CA', 'C'], dtype=object) assert np.all(output == true_output) def test_get_2(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') names, group_indices, group_names = msm.get(molsys, element='atom', selection=[32, 33, 34], name=True, group_index=True, group_name=True) true_names = np.array(['N', 'CA', 'C'], dtype=object) @@ -26,13 +25,11 @@ def test_get_2(): assert np.all(names == true_names) and np.all(group_indices == true_group_indices) and np.all(group_names == true_group_names) def test_get_3(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='atom', selection=[32, 33, 34], n_groups=True) true_n_groups = 1 assert n_groups == true_n_groups def test_get_4(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') names, atom_indices, atom_names = msm.get(molsys, element='group', selection=[10, 11, 12], name=True, atom_index=True, atom_name=True) true_names = np.array(['LYS', 'CYS', 'ASN'], dtype=object) @@ -51,12 +48,10 @@ def test_get_4(): assert check_names and check_atom_indices and check_atom_names def test_get_5(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_atoms = msm.get(molsys, element='group', selection=[10, 11, 12], n_atoms=True) assert np.all(n_atoms==np.array([9, 6, 8])) def test_get_6(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') indices, component_indices = msm.get(molsys, element='group', selection=[550, 551, 552], index=True, component_index=True) true_indices = np.array([550, 551, 552]) @@ -66,13 +61,11 @@ def test_get_6(): assert check_indices and check_component_indices def test_get_7(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_components = msm.get(molsys, element='group', selection=[550, 551, 552], n_components=True) true_n_components = 3 assert n_components==true_n_components def test_get_8(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') indices, component_indices = msm.get(molsys, element='component', selection=[55, 56, 57], index=True, group_index=True) true_indices = np.array([55, 56, 57]) @@ -82,22 +75,18 @@ def test_get_8(): assert check_indices and check_component_indices def test_get_9(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='component', selection=[55, 56, 57], n_groups=True) assert np.all(n_groups==np.array([1, 1, 1])) def test_get_10(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_atoms = msm.get(molsys, element='atom', n_atoms=True) assert n_atoms==3983 def test_get_11(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_chains = msm.get(molsys, element='atom', n_chains=True) assert n_chains==4 def test_get_12(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') atom_names, atom_indices = msm.get(molsys, element='atom', selection='group_index==20', name=True, index=True) true_atom_names = np.array(['N', 'CA', 'C', 'O', 'CB', 'CG', 'CD'], dtype=object) true_atom_indices = np.array([148, 149, 150, 151, 152, 153, 154]) @@ -106,52 +95,43 @@ def test_get_12(): assert check_atom_names and check_atom_indices def test_get_13(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_atoms = msm.get(molsys, element='atom', selection='molecule_type=="protein"', n_atoms=True) assert n_atoms==3818 def test_get_14(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_molecules = msm.get(molsys, element='atom', selection='molecule_type=="water"', n_molecules=True) assert n_molecules==165 def test_get_15(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') atom_names = msm.get(molsys, element='atom', selection=[0, 1, 2], name=True) true_atom_names = np.array(['N', 'CA', 'C'], dtype=object) assert np.all(atom_names==true_atom_names) def test_get_16(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') atom_names = msm.get(molsys, element='atom', selection='atom_index in [0,1,2]', name=True) true_atom_names = np.array(['N', 'CA', 'C'], dtype=object) assert np.all(atom_names==true_atom_names) def test_get_17(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') group_ids = msm.get(molsys, element='atom', selection='atom_index in [0,1,2]', group_id=True) true_group_ids = np.array([4, 4, 4]) assert np.all(group_ids==true_group_ids) def test_get_18(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='atom', selection='atom_index in [0,1,2]', n_groups=True) assert n_groups==1 def test_get_19(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') ids = msm.get(molsys, element='group', selection=[0, 1, 2], id=True) true_ids = np.array([4, 5, 6]) assert np.all(ids==true_ids) def test_get_20(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') ids = msm.get(molsys, element='group', selection='group_index in [0,1,2]', id=True) true_ids = np.array([4, 5, 6]) assert np.all(ids==true_ids) def test_get_21(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') atom_indices = msm.get(molsys, element='group', selection=[0, 1], atom_index=True) true_atom_indices = np.array([np.array([0, 1, 2, 3, 4, 5, 6, 7, 8]), np.array([ 9, 10, 11, 12, 13, 14, 15])], dtype=object) @@ -159,80 +139,67 @@ def test_get_21(): assert check_atom_indices def test_get_22(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') group_indices = msm.get(molsys, element='atom', selection=range(5, 10), group_index=True) true_group_indices = np.array([0, 0, 0, 0, 1]) assert np.all(group_indices==true_group_indices) def test_get_23(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='atom', selection=range(5, 10), n_groups=True) assert n_groups==2 def test_get_24(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') group_indices = msm.get(molsys, element='molecule', selection=[0, 1], group_index=True) true_group_indices = np.array([np.array(range(248)), np.array(range(248, 497))], dtype=object) check_group_indices = np.all([np.all(ii==jj) for ii,jj in zip(group_indices, true_group_indices)]) assert check_group_indices def test_get_25(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') group_names = msm.get(molsys, element='molecule', selection=[3, 4], group_name=True) true_group_names = np.array([['HOH'], ['HOH']], dtype=object) check_group_names = np.all([np.all(ii==jj) for ii,jj in zip(group_names, true_group_names)]) assert check_group_names def test_get_26(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_molecules = msm.get(molsys, element='molecule', selection='molecule_type=="protein"', n_molecules=True) assert n_molecules==2 def test_get_27(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='molecule', selection='molecule_type=="protein"', n_groups=True) true_n_groups = [248, 249] assert np.all(n_groups==true_n_groups) def test_get_28(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='group', selection='molecule_type=="water"', n_groups=True) assert n_groups==165 def test_get_29(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') names = msm.get(molsys, element='entity', selection=0, name=True) true_names = np.array(['Triosephosphate isomerase'], dtype=object) assert np.all(names==true_names) def test_get_30(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') types = msm.get(molsys, element='entity', selection=1, type=True) true_types = np.array(['water'], dtype=object) assert np.all(types==true_types) def test_get_31(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_molecules = msm.get(molsys, element='entity', selection=1, n_molecules=True) true_n_molecules = [165] assert np.all(n_molecules==true_n_molecules) def test_get_32(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') molecule_index = msm.get(molsys, element='entity', selection=1, molecule_index=True) true_molecule_index = np.array([list(range(2, 167))], dtype=object) check_molecule_index = np.all([np.all(ii==jj) for ii,jj in zip(molecule_index, true_molecule_index)]) assert check_molecule_index def test_get_33(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') molecule_types = msm.get(molsys, element='group', selection=[10, 11, 12], molecule_type=True) true_molecule_types = np.array(['protein', 'protein', 'protein'], dtype=object) check_molecule_types = np.all(molecule_types==true_molecule_types) assert check_molecule_types def test_get_34(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') molecule_types = msm.get(molsys, element='molecule', selection=range(1, 10), molecule_type=True) true_molecule_types = np.array(['protein', 'water', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], dtype=object) @@ -240,58 +207,47 @@ def test_get_34(): assert check_molecule_types def test_get_35(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='group', selection='group_type=="aminoacid"', n_groups=True) assert n_groups==497 def test_get_36(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='component', selection=[0, 1], n_groups=True) true_n_groups = [248, 249] assert np.all(n_groups==true_n_groups) def test_get_37(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_groups = msm.get(molsys, element='atom', selection='component_index==[0,1]', n_groups=True) assert n_groups==497 def test_get_38(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_aminoacids = msm.get(molsys, element='system', n_aminoacids=True) assert n_aminoacids==497 def test_get_39(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_waters = msm.get(molsys, element='system', n_waters=True) assert n_waters==165 def test_get_40(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_ions = msm.get(molsys, element='system', n_ions=True) assert n_ions==0 def test_get_41(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_proteins = msm.get(molsys, element='system', n_proteins=True) assert n_proteins==2 def test_get_42(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_rnas = msm.get(molsys, element='system', n_rnas=True) assert n_rnas==0 def test_get_43(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_atoms = msm.get(molsys, element='system', n_atoms=True) assert n_atoms==3983 def test_get_44(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_entities = msm.get(molsys, element='system', n_entities=True) assert n_entities==2 def test_get_45(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') bonded_atoms = msm.get(molsys, element='atom', selection=[0, 1, 2, 3, 4, 5], bonded_atoms=True) true_bonded_atoms = np.array([np.array([1]), np.array([0, 2, 4]), np.array([1, 3, 9]), np.array([2]), np.array([1, 5]), np.array([4, 6])], dtype=object) @@ -299,7 +255,6 @@ def test_get_45(): assert check_bonded_atoms def test_get_46(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') bond_index = msm.get(molsys, element='atom', selection=[0, 1, 2, 3, 4, 5], bond_index=True) true_bond_index = np.array([np.array([0]), np.array([0, 1, 3]), np.array([ 1, 2, 3395]), np.array([2]), np.array([3, 4]), np.array([4, 5])], dtype=object) @@ -307,77 +262,64 @@ def test_get_46(): assert check_bond_index def test_get_47(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_bonds = msm.get(molsys, element='atom', selection=[0, 1, 2, 3, 4, 5], n_bonds=True) true_n_bonds = np.array([1, 3, 3, 1, 2, 2]) assert np.all(n_bonds==true_n_bonds) def test_get_48(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') inner_bonded_atoms = msm.get(molsys, element='atom', selection=[0, 1, 2, 3, 4, 5], inner_bonded_atoms=True) true_inner_bonded_atoms = np.array([[0, 1], [1, 2], [1, 4], [2, 3], [4, 5]]) check_bonded_index = np.all([np.all(ii==jj) for ii,jj in zip(inner_bonded_atoms, true_inner_bonded_atoms)]) assert check_bonded_index def test_get_49(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') inner_bond_index = msm.get(molsys, element='atom', selection=[0, 1, 2, 3, 4, 5], inner_bond_index=True) true_inner_bond_index = np.array([0, 1, 2, 3, 4]) assert np.all(inner_bond_index==true_inner_bond_index) def test_get_50(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_inner_bonds = msm.get(molsys, element='atom', selection=[0, 1, 2, 3, 4, 5], n_inner_bonds=True) assert n_inner_bonds==5 def test_get_51(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') indices = msm.get(molsys, element='bond', selection='group_index==3', index=True) true_indices = np.array([23, 24, 25, 26, 27, 28, 29]) assert np.all(indices==true_indices) def test_get_52(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') atom_indices = msm.get(molsys, element='bond', selection=[0, 1, 2, 3, 4], bonded_atoms=True) atom_indices = atom_indices[np.lexsort((atom_indices[:, 1], atom_indices[:, 0]))] true_atom_indices = np.array([[0, 1], [1, 2], [1, 4], [2, 3], [4, 5]]) assert np.all(atom_indices==true_atom_indices) def test_get_53(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') order = msm.get(molsys, element='bond', selection=[0, 1, 2, 3], order=True) true_order = np.array([1, 1, 2, 1]) assert np.all(order==true_order) def test_get_54(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_bonds = msm.get(molsys, element='bond', selection='group_index==3', n_bonds=True) assert n_bonds==7 def test_get_55(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_bonds = msm.get(molsys, element='system', n_bonds=True) assert n_bonds==3890 def test_get_56(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') n_structures = msm.get(molsys, element='system', n_structures=True) assert n_structures==1 def test_get_57(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') coordinates = msm.get(molsys, element='atom', selection=100, structure_indices=0, coordinates=True) value = msm.pyunitwizard.get_value(coordinates) unit = msm.pyunitwizard.get_unit(coordinates) assert (unit==msm.pyunitwizard.unit('nanometers')) and (np.allclose(value, np.array([[[1.8835, 3.8271, 5.0365]]]))) def test_get_58(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') time = msm.get(molsys, element='system', time=True) assert (time is None) def test_get_59(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') box = msm.get(molsys, element='system', structure_indices=0, box=True) value = msm.pyunitwizard.get_value(box) unit = msm.pyunitwizard.get_unit(box) @@ -387,14 +329,12 @@ def test_get_59(): assert (unit==msm.pyunitwizard.unit('nanometers')) and (np.allclose(value, true_value, atol=1e-06)) def test_get_60(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') box_lengths = msm.get(molsys, element='system', structure_indices=0, box_lengths=True) value = msm.pyunitwizard.get_value(box_lengths) unit = msm.pyunitwizard.get_unit(box_lengths) assert (unit==msm.pyunitwizard.unit('nanometers')) and (np.allclose(value, np.array([[ 4.371 , 7.765 , 14.953999]]))) def test_get_61(): - molsys = msm.convert(tests_systems['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys') box_angles = msm.get(molsys, element='system', structure_indices=0, box_angles=True) value = msm.pyunitwizard.get_value(box_angles) unit = msm.pyunitwizard.get_unit(box_angles) diff --git a/molsysmt/tests/basic/test_is_composed_of.py b/molsysmt/tests/basic/test_is_composed_of.py index f3c707bca..a89d568d5 100644 --- a/molsysmt/tests/basic/test_is_composed_of.py +++ b/molsysmt/tests/basic/test_is_composed_of.py @@ -31,6 +31,6 @@ def test_is_composed_of_5(): assert output == False def test_is_composed_of_6(): - output = msm.is_composed_of(molsys, ions=2, waters=1482, peptides=1) + output = msm.is_composed_of(molsys, ions=2, waters=1258, peptides=1) assert output == True diff --git a/molsysmt/tests/structure/align/test_align_molsysmt_MolSys.py b/molsysmt/tests/structure/align/test_align_molsysmt_MolSys.py index 2e3e4848a..25e3d7348 100644 --- a/molsysmt/tests/structure/align/test_align_molsysmt_MolSys.py +++ b/molsysmt/tests/structure/align/test_align_molsysmt_MolSys.py @@ -25,7 +25,7 @@ def test_get_structure_alignment_molsysmt_MolSys_2(): molsys_1 = msm.extract(molsys_1, selection='molecule_type=="protein"') molsys_2 = msm.convert(tests_systems['T4 lysozyme L99A']['1l17.msmpk'], to_form='molsysmt.MolSys') molsys_2 = msm.convert(molsys_2, to_form='molsysmt.MolSys', selection='molecule_type=="protein"') - molsys_2on1 = msm.structure.align(molsys_2, selection='backbone', + molsys_2on1 = msm.structure.least_rmsd_align(molsys_2, selection='backbone', reference_molecular_system=molsys_1, reference_selection='backbone') identity, int2, int1 = msm.topology.get_sequence_identity(molsys_2, reference_molecular_system=molsys_1) diff --git a/molsysmt/tests/structure/fit/test_fit_from_molsysmt_MolSys.py b/molsysmt/tests/structure/fit/test_fit_from_molsysmt_MolSys.py index 6087fd420..bb5f13a98 100644 --- a/molsysmt/tests/structure/fit/test_fit_from_molsysmt_MolSys.py +++ b/molsysmt/tests/structure/fit/test_fit_from_molsysmt_MolSys.py @@ -12,7 +12,7 @@ def test_fit_molsysmt_MolSys_1(): molsys = msm.convert(tests_systems['pentalanine']['traj_pentalanine.h5'], to_form='molsysmt.MolSys') - fitted_molsys = msm.structure.fit(molsys, selection_fit='backbone', reference_structure_indices=0) + fitted_molsys = msm.structure.least_rmsd_fit(molsys, selection_fit='backbone', reference_structure_indices=0) fitted_rmsd = msm.structure.get_rmsd(fitted_molsys, selection='backbone', reference_structure_indices=0) lrmsd = msm.structure.get_least_rmsd(molsys, selection='backbone', reference_structure_indices=0) check_value_1 = np.allclose(msm.pyunitwizard.get_value(fitted_rmsd, to_unit='nm'), msm.pyunitwizard.get_value(lrmsd, to_unit='nm')) diff --git a/sandbox/Test.ipynb b/sandbox/Test.ipynb index a0a3a0d7f..16c493d6f 100644 --- a/sandbox/Test.ipynb +++ b/sandbox/Test.ipynb @@ -17,7 +17,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "ffee04badb1c4e77ac0e9042b6919d0d", + "model_id": "fa86cde4b6aa4c68bbdc7d30f719e784", "version_major": 2, "version_minor": 0 }, @@ -34,77 +34,117 @@ { "cell_type": "code", "execution_count": 2, - "id": "5b9602f9-f45d-4be0-bd00-8c1302b9c53b", + "id": "62cc52e5-70d2-41c0-be2d-98a3bc2b6526", "metadata": {}, "outputs": [], "source": [ - "psf = msm.systems.demo['POPC']['popc.psf']\n", - "crd = msm.systems.demo['POPC']['popc.crd']" + "molsys = msm.convert(msm.systems.tests['TcTIM']['1tcd.msmpk'], to_form='molsysmt.MolSys')" ] }, { "cell_type": "code", "execution_count": 3, - "id": "717c7c28-35b9-4444-8c16-6d2d407e5ffc", + "id": "23fdfc90-53e7-4276-a778-f518dde4e07f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
formn_atomsn_groupsn_componentsn_chainsn_moleculesn_entitiesn_watersn_proteinsn_structures
molsysmt.MolSys39836621674167216521
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "molsys = msm.convert([psf, crd])" + "msm.info(molsys)" ] }, { "cell_type": "code", "execution_count": 4, - "id": "69737f50-f674-451e-9603-f2afcbe63b22", + "id": "db7f2adb-c433-48a6-83c0-cb3a987d383d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 0, 0, 0, 1])" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#msm.view(molsys)" + "msm.get(molsys, element='atom', selection=range(5, 10), group_index=True)" ] }, { "cell_type": "code", "execution_count": 5, - "id": "6137c17a-7b66-4936-9259-93dec5d44e91", - "metadata": {}, - "outputs": [], - "source": [ - "context = msm.convert(molsys, to_form='openmm.Context')" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "56f0f17f-e468-456f-842f-54f5131eff77", - "metadata": {}, - "outputs": [], - "source": [ - "iterator = msm.Iterator(context, selection = 'all', coordinates = True)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "f093edb5-9864-4f70-8789-6df9689a05f9", + "id": "a7270a80-c18c-4b16-9951-fa60ba9360a2", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" + "ename": "NameError", + "evalue": "name 'np' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[5], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m group_indices \u001b[38;5;241m=\u001b[39m msm\u001b[38;5;241m.\u001b[39mget(molsys, element\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124matom\u001b[39m\u001b[38;5;124m'\u001b[39m, selection\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m5\u001b[39m, \u001b[38;5;241m10\u001b[39m), group_index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m----> 2\u001b[0m true_group_indices \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241m.\u001b[39marray([\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m])\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m np\u001b[38;5;241m.\u001b[39mall(group_indices\u001b[38;5;241m==\u001b[39mtrue_group_indices)\n", + "\u001b[0;31mNameError\u001b[0m: name 'np' is not defined" ] } ], "source": [ - "for aux_coordinates in iterator:\n", - " print(len(aux_coordinates))" + "group_indices = msm.get(molsys, element='atom', selection=range(5, 10), group_index=True)\n", + "true_group_indices = np.array([0, 0, 0, 0, 1])\n", + "assert np.all(group_indices==true_group_indices)" ] }, { "cell_type": "code", "execution_count": null, - "id": "22b588a1-dfa0-4d1a-b4fc-777876bf4366", + "id": "013d0f3e-05a5-4f7e-a21e-3b2a0be35e65", "metadata": {}, "outputs": [], "source": []