Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed May 6, 2024
1 parent 0fcfb00 commit 960daa7
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 64 deletions.
14 changes: 7 additions & 7 deletions molsysmt/_private/common_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

13 changes: 8 additions & 5 deletions molsysmt/_private/digestion/argument/keep_ids.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions molsysmt/build/is_solvated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand All @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion molsysmt/build/mutate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 4 additions & 0 deletions molsysmt/form/molsysmt_MolSys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions molsysmt/form/molsysmt_MolSys/to_string_amino_acids_1.py
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions molsysmt/form/molsysmt_MolSys/to_string_amino_acids_3.py
Original file line number Diff line number Diff line change
@@ -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

3 changes: 0 additions & 3 deletions molsysmt/form/molsysmt_Structures/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions molsysmt/form/pdbfixer_PDBFixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions molsysmt/form/string_pdb_id/get_structural_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion molsysmt/pbc/get_angles_from_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand Down
2 changes: 1 addition & 1 deletion molsysmt/pbc/get_lengths_from_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand Down
6 changes: 3 additions & 3 deletions molsysmt/pbc/get_shape_from_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand All @@ -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)

2 changes: 1 addition & 1 deletion molsysmt/pbc/get_shape_from_lengths_and_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand Down
4 changes: 2 additions & 2 deletions molsysmt/pbc/has_pbc.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 6 additions & 6 deletions molsysmt/pbc/unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand All @@ -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)
Expand All @@ -35,18 +35,18 @@ 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)

gc.collect()

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)

Expand Down
16 changes: 8 additions & 8 deletions molsysmt/pbc/wrap_to_mic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
"""
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 960daa7

Please sign in to comment.