From 960daa719235c05ff7ceff2fe388e01f255fe157 Mon Sep 17 00:00:00 2001 From: Diego Prada-Gracia Date: Sun, 5 May 2024 23:10:29 -0600 Subject: [PATCH] In process --- molsysmt/_private/common_get.py | 14 ++--- .../_private/digestion/argument/keep_ids.py | 13 +++-- molsysmt/build/is_solvated.py | 4 +- molsysmt/build/mutate.py | 2 +- molsysmt/form/molsysmt_MolSys/__init__.py | 4 ++ .../to_string_amino_acids_1.py | 13 +++++ .../to_string_amino_acids_3.py | 12 +++++ molsysmt/form/molsysmt_Structures/get.py | 3 -- molsysmt/form/pdbfixer_PDBFixer/__init__.py | 2 + .../get_structural_attributes.py | 11 ++++ molsysmt/pbc/get_angles_from_box.py | 2 +- molsysmt/pbc/get_lengths_from_box.py | 2 +- molsysmt/pbc/get_shape_from_box.py | 6 +-- .../pbc/get_shape_from_lengths_and_angles.py | 2 +- molsysmt/pbc/has_pbc.py | 4 +- molsysmt/pbc/unwrap.py | 12 ++--- molsysmt/pbc/wrap_to_mic.py | 16 +++--- .../test_add_missing_terminal_cappings.py | 2 +- .../test_build_peptide_molsysmt_MolSys.py | 2 +- .../test_is_solvated_molsysmt_MolSys.py | 4 +- .../mutate/test_mutate_molsysmt_MolSys.py | 20 ++++---- .../solvate/test_solvate_molsysmt_MolSys.py | 8 +-- ...est_solve_atoms_with_alternate_location.py | 6 +-- sandbox/Tests.ipynb | 51 +++++++++++++++++-- 24 files changed, 151 insertions(+), 64 deletions(-) create mode 100644 molsysmt/form/molsysmt_MolSys/to_string_amino_acids_1.py create mode 100644 molsysmt/form/molsysmt_MolSys/to_string_amino_acids_3.py diff --git a/molsysmt/_private/common_get.py b/molsysmt/_private/common_get.py index 25328bd55..a56fceedc 100644 --- a/molsysmt/_private/common_get.py +++ b/molsysmt/_private/common_get.py @@ -263,7 +263,7 @@ def get_n_atoms_from_atom(item, indices='all'): if is_all(indices): output = get_n_atoms_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output @@ -900,7 +900,7 @@ def get_n_groups_from_group(item, indices='all'): if is_all(indices): output = get_n_groups_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output @@ -1535,7 +1535,7 @@ def get_n_components_from_component(item, indices='all'): if is_all(indices): output = get_n_components_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output @@ -2232,7 +2232,7 @@ def get_n_molecules_from_molecule(item, indices='all'): if is_all(indices): output = get_n_molecules_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output @@ -2935,7 +2935,7 @@ def get_n_chains_from_chain(item, indices='all'): if is_all(indices): output = get_n_chains_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output @@ -3658,7 +3658,7 @@ def get_n_entities_from_entity(item, indices='all'): if is_all(indices): output = get_n_entities_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output @@ -4070,7 +4070,7 @@ def get_n_bonds_from_bond(item, indices='all'): if is_all(indices): output = get_n_bonds_from_system(item) else: - output = indices.shape[0] + output = len(indices) return output diff --git a/molsysmt/_private/digestion/argument/keep_ids.py b/molsysmt/_private/digestion/argument/keep_ids.py index 3090bb351..fa946bd61 100644 --- a/molsysmt/_private/digestion/argument/keep_ids.py +++ b/molsysmt/_private/digestion/argument/keep_ids.py @@ -1,12 +1,15 @@ from ...exceptions import ArgumentError -def digest_keep_ids(keep_ids, caller=None): +functions_with_boolean = ( + 'merge.merge', + 'add.add', + 'add_missing_terminal_cappings.add_missing_terminal_cappings' + ) - if caller.endswith('.merge.merge'): - if isinstance(keep_ids, bool): - return keep_ids - if caller.endswith('.add.add'): +def digest_keep_ids(keep_ids, caller=None): + + if caller.endswith(functions_with_boolean): if isinstance(keep_ids, bool): return keep_ids diff --git a/molsysmt/build/is_solvated.py b/molsysmt/build/is_solvated.py index 30279fae0..0cfabebf9 100644 --- a/molsysmt/build/is_solvated.py +++ b/molsysmt/build/is_solvated.py @@ -2,7 +2,7 @@ from molsysmt import pyunitwizard as puw @digest() -def is_solvated(molecular_system): +def is_solvated(molecular_system, skip_digestion=False): """ To be written soon... """ @@ -11,7 +11,7 @@ def is_solvated(molecular_system): output = False - n_waters, volume = get(molecular_system, element='system', n_waters=True, box_volume=True) + n_waters, volume = get(molecular_system, element='system', n_waters=True, box_volume=True, skip_digestion=True) if (n_waters>0) and (volume is not None): diff --git a/molsysmt/build/mutate.py b/molsysmt/build/mutate.py index 621e49e1a..72b5363c3 100644 --- a/molsysmt/build/mutate.py +++ b/molsysmt/build/mutate.py @@ -40,7 +40,7 @@ def mutate(molecular_system, mutations=None, keys='group_index', selection="all" aux_indices = get(molecular_system, element='group', selection='group_id==@ii', mask=selection, group_index=True) - if aux_indices.shape[0]>1: + if len(aux_indices)>1: raise ValueError(f'There are multiple groups with the group_id: {ii}') else: group_indices.append(aux_indices[0]) diff --git a/molsysmt/form/molsysmt_MolSys/__init__.py b/molsysmt/form/molsysmt_MolSys/__init__.py index 86e380643..789cc869a 100644 --- a/molsysmt/form/molsysmt_MolSys/__init__.py +++ b/molsysmt/form/molsysmt_MolSys/__init__.py @@ -43,6 +43,8 @@ from .to_file_h5msm import to_file_h5msm from .to_file_pdb import to_file_pdb from .to_string_pdb_text import to_string_pdb_text +from .to_string_amino_acids_1 import to_string_amino_acids_1 +from .to_string_amino_acids_3 import to_string_amino_acids_3 _convert_to={ 'molsysmt.MolSys': extract, @@ -59,6 +61,8 @@ 'openmm.Modeller': to_openmm_Modeller, 'pdbfixer.PDBFixer': to_pdbfixer_PDBFixer, 'string:pdb_text': to_string_pdb_text, + 'string:amino_acids_1': to_string_amino_acids_1, + 'string:amino_acids_3': to_string_amino_acids_3, 'file:msmpk': to_file_msmpk, 'file:h5msm': to_file_h5msm, 'file:pdb': to_file_pdb, diff --git a/molsysmt/form/molsysmt_MolSys/to_string_amino_acids_1.py b/molsysmt/form/molsysmt_MolSys/to_string_amino_acids_1.py new file mode 100644 index 000000000..539a70c6d --- /dev/null +++ b/molsysmt/form/molsysmt_MolSys/to_string_amino_acids_1.py @@ -0,0 +1,13 @@ +from molsysmt._private.digestion import digest + +@digest(form='molsysmt.MolSys') +def to_string_amino_acids_1(item, group_indices='all', skip_digestion=False): + + from . import to_molsysmt_Topology + from ..molsysmt_Topology import to_string_amino_acids_1 as molsysmt_Topology_to_string_amino_acids_1 + + tmp_item = to_molsysmt_Topology(item, skip_digestion=True) + tmp_item = molsysmt_Topology_to_string_amino_acids_1(tmp_item, group_indices=group_indices, skip_digestion=True) + + return tmp_item + diff --git a/molsysmt/form/molsysmt_MolSys/to_string_amino_acids_3.py b/molsysmt/form/molsysmt_MolSys/to_string_amino_acids_3.py new file mode 100644 index 000000000..c1ec42f02 --- /dev/null +++ b/molsysmt/form/molsysmt_MolSys/to_string_amino_acids_3.py @@ -0,0 +1,12 @@ +from molsysmt._private.digestion import digest +import numpy as np + +@digest(form='molsysmt.MolSys') +def to_string_amino_acids_3(item, group_indices='all', skip_digestion=False): + + from ..molsysmt_Topology import to_string_amino_acids_3 as molsysmt_Topology_to_string_amino_acids_3 + + tmp_item = molsysmt_Topology_to_string_amino_acids_3(item.topology, group_indices=group_indices, skip_digestion=True) + + return tmp_item + diff --git a/molsysmt/form/molsysmt_Structures/get.py b/molsysmt/form/molsysmt_Structures/get.py index 1af130ba3..b234d71cf 100644 --- a/molsysmt/form/molsysmt_Structures/get.py +++ b/molsysmt/form/molsysmt_Structures/get.py @@ -218,9 +218,6 @@ def get_box_volume_from_system(item, structure_indices='all', skip_digestion=Fal if structure_indices is None: return None - if item.time is None: - return None - from molsysmt.pbc import get_volume_from_box output = None box = get_box_from_system(item, structure_indices=structure_indices, skip_digestion=True) diff --git a/molsysmt/form/pdbfixer_PDBFixer/__init__.py b/molsysmt/form/pdbfixer_PDBFixer/__init__.py index 05df6916d..6e37f629c 100644 --- a/molsysmt/form/pdbfixer_PDBFixer/__init__.py +++ b/molsysmt/form/pdbfixer_PDBFixer/__init__.py @@ -5,6 +5,8 @@ piped_topological_attribute = None piped_structural_attribute = None piped_any_attribute = None +bonds_are_explicit = True +bonds_can_be_computed = True from .is_form import is_form diff --git a/molsysmt/form/string_pdb_id/get_structural_attributes.py b/molsysmt/form/string_pdb_id/get_structural_attributes.py index 6f6fc3681..f94b883a7 100644 --- a/molsysmt/form/string_pdb_id/get_structural_attributes.py +++ b/molsysmt/form/string_pdb_id/get_structural_attributes.py @@ -163,6 +163,17 @@ def get_n_bioassemblies_from_system(item, skip_digestion=False): return output +@digest(form=form) +def get_alternate_location_from_system (item, skip_digestion=False): + + from . import to_mmtf_MMTFDecoder + from ..mmtf_MMTFDecoder import get_alternate_location_from_system as aux_get + + tmp_item = to_mmtf_MMTFDecoder(item, skip_digestion=True) + output = aux_get(tmp_item, skip_digestion=True) + + return output + # List of functions to be imported diff --git a/molsysmt/pbc/get_angles_from_box.py b/molsysmt/pbc/get_angles_from_box.py index c5e89650a..577ddaf8b 100644 --- a/molsysmt/pbc/get_angles_from_box.py +++ b/molsysmt/pbc/get_angles_from_box.py @@ -3,7 +3,7 @@ from molsysmt import lib as msmlib @digest() -def get_angles_from_box(box): +def get_angles_from_box(box, skip_digestion=False): """ To be written soon... """ diff --git a/molsysmt/pbc/get_lengths_from_box.py b/molsysmt/pbc/get_lengths_from_box.py index 7053e3621..8e742410a 100644 --- a/molsysmt/pbc/get_lengths_from_box.py +++ b/molsysmt/pbc/get_lengths_from_box.py @@ -3,7 +3,7 @@ from molsysmt import lib as msmlib @digest() -def get_lengths_from_box(box): +def get_lengths_from_box(box, skip_digestion=False): """ To be written soon... """ diff --git a/molsysmt/pbc/get_shape_from_box.py b/molsysmt/pbc/get_shape_from_box.py index 0334b0b4d..ff6dc6dd5 100644 --- a/molsysmt/pbc/get_shape_from_box.py +++ b/molsysmt/pbc/get_shape_from_box.py @@ -3,7 +3,7 @@ import numpy as np @digest() -def get_shape_from_box(box): +def get_shape_from_box(box, skip_digestion=False): """ To be written soon... """ @@ -15,6 +15,6 @@ def get_shape_from_box(box): return None else: - lengths, angles = get_lengths_and_angles_from_box(box) - return get_shape_from_lengths_and_angles(lengths, angles) + lengths, angles = get_lengths_and_angles_from_box(box, skip_digestion=True) + return get_shape_from_lengths_and_angles(lengths, angles, skip_digestion=True) diff --git a/molsysmt/pbc/get_shape_from_lengths_and_angles.py b/molsysmt/pbc/get_shape_from_lengths_and_angles.py index c6a542f9d..343dfbcc8 100644 --- a/molsysmt/pbc/get_shape_from_lengths_and_angles.py +++ b/molsysmt/pbc/get_shape_from_lengths_and_angles.py @@ -3,7 +3,7 @@ from molsysmt import pyunitwizard as puw @digest() -def get_shape_from_lengths_and_angles(box_lengths, box_angles): +def get_shape_from_lengths_and_angles(box_lengths, box_angles, skip_digestion=False): """ To be written soon... """ diff --git a/molsysmt/pbc/has_pbc.py b/molsysmt/pbc/has_pbc.py index caeebdcdb..1ceed3b7f 100644 --- a/molsysmt/pbc/has_pbc.py +++ b/molsysmt/pbc/has_pbc.py @@ -1,14 +1,14 @@ from molsysmt._private.digestion import digest @digest() -def has_pbc(molecular_system): +def has_pbc(molecular_system, skip_digestion=False): """ To be written soon... """ from molsysmt import get - box = get(molecular_system, structure_indices=0, box=True) + box = get(molecular_system, structure_indices=0, box=True, skip_digestion=True) output = True diff --git a/molsysmt/pbc/unwrap.py b/molsysmt/pbc/unwrap.py index 36d6e2b6c..5c1da07a5 100644 --- a/molsysmt/pbc/unwrap.py +++ b/molsysmt/pbc/unwrap.py @@ -7,7 +7,7 @@ @digest() def unwrap(molecular_system, selection='all', structure_indices='all', - syntax='MolSysMT', engine='MolSysMT', in_place=False): + syntax='MolSysMT', engine='MolSysMT', in_place=False, skip_digestion=False): """ To be written soon... """ @@ -16,10 +16,10 @@ def unwrap(molecular_system, selection='all', structure_indices='all', from molsysmt.basic import select, get, set, extract, copy - coordinates= get(molecular_system, element='atom', selection=selection, coordinates=True) + coordinates= get(molecular_system, element='atom', selection=selection, coordinates=True, skip_digestion=True) n_structures = coordinates.shape[0] n_atoms = coordinates.shape[1] - box = get(molecular_system, element='system', structure_indices=structure_indices, box=True) + box = get(molecular_system, element='system', structure_indices=structure_indices, box=True, skip_digestion=True) coordinates, length_units = puw.get_value_and_unit(coordinates) box = puw.get_value(box, to_unit=length_units) @@ -35,7 +35,7 @@ def unwrap(molecular_system, selection='all', structure_indices='all', if in_place: set(molecular_system, selection=selection, structure_indices=structure_indices, - syntax=syntax, coordinates=coordinates) + syntax=syntax, coordinates=coordinates, skip_digestion=True) del(coordinates, box) @@ -43,10 +43,10 @@ def unwrap(molecular_system, selection='all', structure_indices='all', else: - tmp_molecular_system = copy(molecular_system) + tmp_molecular_system = copy(molecular_system, skip_digestion=True) set(tmp_molecular_system, selection=selection, structure_indices=structure_indices, - syntax='MolSysMT', coordinates=coordinates) + syntax='MolSysMT', coordinates=coordinates, skip_digestion=True) del(coordinates, box) diff --git a/molsysmt/pbc/wrap_to_mic.py b/molsysmt/pbc/wrap_to_mic.py index 6aeb024e5..0b94dfe0c 100644 --- a/molsysmt/pbc/wrap_to_mic.py +++ b/molsysmt/pbc/wrap_to_mic.py @@ -9,7 +9,7 @@ def wrap_to_mic(molecular_system, selection='all', structure_indices='all', center_coordinates='[0,0,0] nanometers', center_of_selection=None, weights=None, center_at_origin=True, keep_covalent_bonds=False, - syntax='MolSysMT', engine='MolSysMT', in_place=False): + syntax='MolSysMT', engine='MolSysMT', in_place=False, skip_digestion=False): """ To be written soon... """ @@ -19,16 +19,16 @@ def wrap_to_mic(molecular_system, selection='all', structure_indices='all', from molsysmt.basic import select, get, set, extract, copy from molsysmt.structure import get_center - atom_indices = select(molecular_system, selection=selection, syntax=syntax) + atom_indices = select(molecular_system, selection=selection, syntax=syntax, skip_digestion=True) - coordinates= get(molecular_system, element='atom', selection=atom_indices, coordinates=True) - box = get(molecular_system, element='system', structure_indices=structure_indices, box=True) + coordinates= get(molecular_system, element='atom', selection=atom_indices, coordinates=True, skip_digestion=True) + box = get(molecular_system, element='system', structure_indices=structure_indices, box=True, skip_digestion=True) if center_of_selection is not None: center_coordinates = get_center(molecular_system, selection=center_of_selection, weights=weights, structure_indices=structure_indices, - syntax=syntax, engine='MolSysMT') + syntax=syntax, engine='MolSysMT', skip_digestion=True) coordinates, length_units = puw.get_value_and_unit(coordinates) box = puw.get_value(box, to_unit=length_units) @@ -47,7 +47,7 @@ def wrap_to_mic(molecular_system, selection='all', structure_indices='all', if in_place: set(molecular_system, selection='atom_index in @atom_indices', structure_indices=structure_indices, - syntax=syntax, coordinates=coordinates) + syntax=syntax, coordinates=coordinates, skip_digestion=True) del(coordinates, atom_indices, structure_indices) @@ -57,9 +57,9 @@ def wrap_to_mic(molecular_system, selection='all', structure_indices='all', else: - tmp_molecular_system = copy(molecular_system) + tmp_molecular_system = copy(molecular_system, skip_digestion=True) set(tmp_molecular_system, selection='atom_index in @atom_indices', structure_indices=structure_indices, - syntax=syntax, coordinates=coordinates) + syntax=syntax, coordinates=coordinates, skip_digestion=True) del(coordinates, atom_indices, structure_indices) diff --git a/molsysmt/tests/build/add_missing_terminal_cappings/test_add_missing_terminal_cappings.py b/molsysmt/tests/build/add_missing_terminal_cappings/test_add_missing_terminal_cappings.py index d59602eb8..e5fd3d11c 100644 --- a/molsysmt/tests/build/add_missing_terminal_cappings/test_add_missing_terminal_cappings.py +++ b/molsysmt/tests/build/add_missing_terminal_cappings/test_add_missing_terminal_cappings.py @@ -4,7 +4,7 @@ # Import package, test suite, and other packages as needed import molsysmt as msm -from molsysmt.systems import tests as tests_systems +from molsysmt import systems import numpy as np import os diff --git a/molsysmt/tests/build/build_peptide/test_build_peptide_molsysmt_MolSys.py b/molsysmt/tests/build/build_peptide/test_build_peptide_molsysmt_MolSys.py index 27c0ba260..e7a570025 100644 --- a/molsysmt/tests/build/build_peptide/test_build_peptide_molsysmt_MolSys.py +++ b/molsysmt/tests/build/build_peptide/test_build_peptide_molsysmt_MolSys.py @@ -12,7 +12,7 @@ def test_build_peptide_molsysmt_MolSys_1(): seq = 'TyrGlyGlyPheMet' molsys = msm.build.build_peptide(seq, to_form='molsysmt.MolSys') - seq_2 = msm.convert(molsys, to_form='string:aminoacids3') + seq_2 = msm.convert(molsys, to_form='string:amino_acids_3') assert seq.lower()==seq_2.lower() #def test_build_peptide_molsysmt_MolSys_2(): diff --git a/molsysmt/tests/build/is_solvated/test_is_solvated_molsysmt_MolSys.py b/molsysmt/tests/build/is_solvated/test_is_solvated_molsysmt_MolSys.py index 3dfdd9234..5ad1551be 100644 --- a/molsysmt/tests/build/is_solvated/test_is_solvated_molsysmt_MolSys.py +++ b/molsysmt/tests/build/is_solvated/test_is_solvated_molsysmt_MolSys.py @@ -6,13 +6,13 @@ # Import package, test suite, and other packages as needed import pytest import molsysmt as msm -from molsysmt.systems import tests as tests_systems +from molsysmt import systems import numpy as np # Distance between atoms in space and time def test_is_solvate_molsysmt_MolSys_1(): - molsys = msm.convert(tests_systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') molsys = msm.build.add_missing_terminal_cappings(molsys) molsys = msm.build.add_missing_hydrogens(molsys) output_before = msm.build.is_solvated(molsys) diff --git a/molsysmt/tests/build/mutate/test_mutate_molsysmt_MolSys.py b/molsysmt/tests/build/mutate/test_mutate_molsysmt_MolSys.py index fcaa31719..3916d44b5 100644 --- a/molsysmt/tests/build/mutate/test_mutate_molsysmt_MolSys.py +++ b/molsysmt/tests/build/mutate/test_mutate_molsysmt_MolSys.py @@ -5,35 +5,35 @@ # Import package, test suite, and other packages as needed import molsysmt as msm -from molsysmt.systems import tests as tests_systems +from molsysmt import systems import numpy as np # Distance between atoms in space and time def test_mutate_molsysmt_MolSys_1(): - molsys = msm.convert(tests_systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') molsys = msm.build.mutate(molsys, mutations={1:'ALA', 2:'VAL'}, keys='group_index') - seq = msm.convert(molsys, to_form='string:aminoacids3') + seq = msm.convert(molsys, to_form='string:amino_acids_3') check = (seq == 'TyrAlaValPheMet') assert check def test_mutate_molsysmt_MolSys_2(): - molsys = msm.convert(tests_systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') molsys = msm.build.mutate(molsys, mutations={2:'ALA', 3:'VAL'}, keys='group_id') - seq = msm.convert(molsys, to_form='string:aminoacids3') + seq = msm.convert(molsys, to_form='string:amino_acids_3') check = (seq == 'TyrAlaValPheMet') assert check def test_mutate_molsysmt_MolSys_3(): - molsys = msm.convert(tests_systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['Met-enkephalin']['met_enkephalin.pdb'], to_form='molsysmt.MolSys') molsys = msm.build.mutate(molsys, mutations={'GLY':'ALA'}, keys='group_name') - seq = msm.convert(molsys, to_form='string:aminoacids3') + seq = msm.convert(molsys, to_form='string:amino_acids_3') check = (seq == 'TyrAlaAlaPheMet') assert check # From https://github.com/openmm/pdbfixer/blob/master/pdbfixer/tests/test_mutate.py def test_mutate_molsysmt_MolSys_4(): - molsys = msm.convert(tests_systems['chicken villin HP35']['1vii.mmtf'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['chicken villin HP35']['1vii.mmtf'], to_form='molsysmt.MolSys') molsys = msm.build.mutate(molsys, mutations="ALA-57-GLY") group_name, group_id = msm.get(molsys, element='group', selection="group_index==16", group_name=True, group_id=True) atoms = msm.get(molsys, element='atom', selection="group_index==16", atom_name=True) @@ -43,8 +43,8 @@ def test_mutate_molsysmt_MolSys_4(): # From https://github.com/openmm/pdbfixer/blob/master/pdbfixer/tests/test_mutate.py def test_mutate_molsysmt_MolSys_5(): - molsys = msm.convert(tests_systems['chicken villin HP35']['1vii.mmtf'], to_form='molsysmt.MolSys') - molsys = msm.build.mutate(molsys, mutations=["ALA-57-LEU", "SER-56-ALA"], selection="chain_id=='A'") + molsys = msm.convert(systems['chicken villin HP35']['1vii.mmtf'], to_form='molsysmt.MolSys') + molsys = msm.build.mutate(molsys, mutations=["ALA-57-LEU", "SER-56-ALA"], selection="chain_name=='A'") group_name57, group_id57 = msm.get(molsys, element='group', selection="group_index==16", group_name=True, group_id=True) group_name56, group_id56 = msm.get(molsys, element='group', selection="group_index==15", group_name=True, group_id=True) atoms57 = msm.get(molsys, element='atom', selection="group_index==16", atom_name=True) diff --git a/molsysmt/tests/build/solvate/test_solvate_molsysmt_MolSys.py b/molsysmt/tests/build/solvate/test_solvate_molsysmt_MolSys.py index c0f6e4e67..3502414d1 100644 --- a/molsysmt/tests/build/solvate/test_solvate_molsysmt_MolSys.py +++ b/molsysmt/tests/build/solvate/test_solvate_molsysmt_MolSys.py @@ -6,13 +6,13 @@ # Import package, test suite, and other packages as needed import pytest import molsysmt as msm -from molsysmt.systems import tests as tests_systems +from molsysmt import systems import numpy as np # Distance between atoms in space and time def test_solvate_molsysmt_MolSys_1(): - molsys = msm.convert(tests_systems['chicken villin HP35']['chicken_villin_HP35.msmpk'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['chicken villin HP35']['chicken_villin_HP35.h5msm'], to_form='molsysmt.MolSys') molsys = msm.build.add_missing_terminal_cappings(molsys) molsys = msm.build.add_missing_hydrogens(molsys) molsys = msm.build.solvate([molsys, {'forcefield':'AMBER14', 'water_model':'TIP3P'}], @@ -25,7 +25,7 @@ def test_solvate_molsysmt_MolSys_1(): assert n_ions==2 def test_solvate_molsysmt_MolSys_2(): - molsys = msm.convert(tests_systems['chicken villin HP35']['chicken_villin_HP35.msmpk'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['chicken villin HP35']['chicken_villin_HP35.h5msm'], to_form='molsysmt.MolSys') molsys = msm.build.add_missing_terminal_cappings(molsys) molsys = msm.build.add_missing_hydrogens(molsys) molsys = msm.build.solvate([molsys, {'forcefield':'AMBER14', 'water_model':'TIP3P'}], @@ -36,7 +36,7 @@ def test_solvate_molsysmt_MolSys_2(): assert 'truncated octahedral'==box_shape def test_solvate_molsysmt_MolSys_3(): - molsys = msm.convert(tests_systems['chicken villin HP35']['chicken_villin_HP35.msmpk'], to_form='molsysmt.MolSys') + molsys = msm.convert(systems['chicken villin HP35']['chicken_villin_HP35.h5msm'], to_form='molsysmt.MolSys') molsys = msm.build.add_missing_terminal_cappings(molsys) molsys = msm.build.add_missing_hydrogens(molsys) molsys = msm.build.solvate([molsys, {'forcefield':'AMBER14', 'water_model':'TIP3P'}], diff --git a/molsysmt/tests/build/solve_atoms_with_alternate_location/test_solve_atoms_with_alternate_location.py b/molsysmt/tests/build/solve_atoms_with_alternate_location/test_solve_atoms_with_alternate_location.py index 3e7da1749..164a42609 100644 --- a/molsysmt/tests/build/solve_atoms_with_alternate_location/test_solve_atoms_with_alternate_location.py +++ b/molsysmt/tests/build/solve_atoms_with_alternate_location/test_solve_atoms_with_alternate_location.py @@ -4,7 +4,7 @@ # Import package, test suite, and other packages as needed import molsysmt as msm -from molsysmt.systems import tests as tests_systems +from molsysmt import systems from molsysmt import pyunitwizard as puw import numpy as np import os @@ -35,7 +35,7 @@ def test_solve_atoms_with_alternate_location_molsysmt_MolSys_1(): def test_solve_atoms_with_alternate_location_molsysmt_MolSys_2(): - molecular_system = msm.convert(tests_systems['Barnase-Barstar']['1brs.mmtf'], to_form='molsysmt.MolSys') + molecular_system = msm.convert(systems['Barnase-Barstar']['1brs.mmtf'], to_form='molsysmt.MolSys') msm.build.solve_atoms_with_alternate_location(molecular_system, location_id='B') atom_id, b_factor, occupancy, coordinates = msm.get(molecular_system, element='atom', selection=[2686,2687], atom_id=True, b_factor=True, occupancy=True, coordinates=True) @@ -48,7 +48,7 @@ def test_solve_atoms_with_alternate_location_molsysmt_MolSys_2(): def test_solve_atoms_with_alternate_location_molsysmt_MolSys_3(): - molecular_system = msm.convert(tests_systems['Barnase-Barstar']['1brs.mmtf'], to_form='molsysmt.MolSys') + molecular_system = msm.convert(systems['Barnase-Barstar']['1brs.mmtf'], to_form='molsysmt.MolSys') msm.build.solve_atoms_with_alternate_location(molecular_system, selection=[2686,2687], location_id=['A','B']) atom_id, b_factor, occupancy, coordinates = msm.get(molecular_system, element='atom', selection=[2686,2687], atom_id=True, b_factor=True, occupancy=True, coordinates=True) diff --git a/sandbox/Tests.ipynb b/sandbox/Tests.ipynb index 721e55884..98895ec19 100644 --- a/sandbox/Tests.ipynb +++ b/sandbox/Tests.ipynb @@ -28,7 +28,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "0811f066e5394efeb5ee09e8c0319569", + "model_id": "22c65faea8804672ae2053b6f84bfb84", "version_major": 2, "version_minor": 0 }, @@ -53,13 +53,58 @@ "import numpy as np" ] }, + { + "cell_type": "code", + "execution_count": 7, + "id": "10c50058-2459-4e9e-a3f3-3cf520a6e5be", + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "module 'molsysmt.form.string_pdb_id' has no attribute 'get_alternate_location_from_system'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m alt_loc \u001b[38;5;241m=\u001b[39m \u001b[43mmsm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m1BRS\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43malternate_location\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/_private/digestion/digest.py:122\u001b[0m, in \u001b[0;36mdigest..digestor..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(all_args[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mself\u001b[39m\u001b[38;5;124m'\u001b[39m], \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mfinal_args)\n\u001b[1;32m 121\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 122\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mfinal_args\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/basic/get.py:199\u001b[0m, in \u001b[0;36mget\u001b[0;34m(molecular_system, element, selection, structure_indices, mask, syntax, get_missing_bonds, output_type, skip_digestion, **kwargs)\u001b[0m\n\u001b[1;32m 197\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 198\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 199\u001b[0m aux_get \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mgetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m_dict_modules\u001b[49m\u001b[43m[\u001b[49m\u001b[43maux_form\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mget_\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43min_attribute\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m_from_\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43melement\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 200\u001b[0m result \u001b[38;5;241m=\u001b[39m aux_get(aux_item, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mdict_indices)\n\u001b[1;32m 202\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "\u001b[0;31mAttributeError\u001b[0m: module 'molsysmt.form.string_pdb_id' has no attribute 'get_alternate_location_from_system'" + ] + } + ], + "source": [ + "alt_loc = msm.get('1BRS', alternate_location=True)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "175c9905-31b2-44a0-9d9f-8293035a16e5", + "id": "6ea69210-eccc-415b-9608-0b4cf842136e", "metadata": {}, "outputs": [], - "source": [] + "source": [ + " alt_loc = msm.get('1BRS', alternate_location=True)\n", + " assert np.all(list(alt_loc[0].keys())==[2686,2687])\n", + "\n", + " alt_loc_1 = alt_loc[0][2686]\n", + " assert np.all(alt_loc_1['location_id']==np.array(['A','B']))\n", + " assert np.all(alt_loc_1['occupancy']==np.array([0.5,0.5]))\n", + " assert np.all(alt_loc_1['atom_id']==np.array([2687,2688]))\n", + " aux_coors = puw.quantity(np.array([[3.2742, 2.2579, 0.1536], [3.2757, 2.2571, 0.1533]]),'nm')\n", + " assert puw.are_close(alt_loc_1['coordinates'], aux_coors)\n", + " aux_b_factor = puw.quantity(np.array([0.2466, 0.2467]),'nm**2')\n", + " assert puw.are_close(alt_loc_1['b_factor'], aux_b_factor)\n", + "\n", + " alt_loc_2 = alt_loc[0][2687]\n", + " assert np.all(alt_loc_2['location_id']==np.array(['A','B']))\n", + " assert np.all(alt_loc_2['occupancy']==np.array([0.5,0.5]))\n", + " assert np.all(alt_loc_2['atom_id']==np.array([2689,2690]))\n", + " aux_coors = puw.quantity(np.array([[3.1412, 2.241 , 0.1076], [3.3396, 2.192 , 0.2619]]),'nm')\n", + " assert puw.are_close(alt_loc_2['coordinates'], aux_coors)\n", + " aux_b_factor = puw.quantity(np.array([0.2594, 0.2596]),'nm**2')\n", + " assert puw.are_close(alt_loc_2['b_factor'], aux_b_factor)\n" + ] } ], "metadata": {