Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed May 3, 2024
1 parent 99c209a commit c29d492
Show file tree
Hide file tree
Showing 36 changed files with 281 additions and 518 deletions.
27 changes: 6 additions & 21 deletions molsysmt/_private/conversion_shortcuts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,40 @@
_multiple_conversion_shortcuts = {}


from .to_molsysmt_MolSys import molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_MolSys
from .to_molsysmt_MolSys import file_prmtop_and_file_inpcrd_to_molsysmt_MolSys
from .to_molsysmt_MolSys import file_psf_and_file_dcd_to_molsysmt_MolSys
from .to_molsysmt_MolSys import file_psf_and_file_crd_to_molsysmt_MolSys
from .to_molsysmt_MolSys import file_gro_and_file_xtc_to_molsysmt_MolSys

_multiple_conversion_shortcuts[tuple(sorted(('molsysmt.Topology','molsysmt.Structures')))]={
'molsysmt.MolSys': molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_MolSys
}

_multiple_conversion_shortcuts[tuple(sorted(('file:prmtop','file:inpcrd')))]={
'molsysmt.MolSys': file_prmtop_and_file_inpcrd_to_molsysmt_MolSys
}

_multiple_conversion_shortcuts[tuple(sorted(('file:psf','file:dcd')))]={
'molsysmt.MolSys': file_psf_and_file_dcd_to_molsysmt_MolSys
}

_multiple_conversion_shortcuts[tuple(sorted(('file:psf','file:crd')))]={
'molsysmt.MolSys': file_psf_and_file_crd_to_molsysmt_MolSys
}

_multiple_conversion_shortcuts[tuple(sorted(('file:gro','file:xtc')))]={
'molsysmt.MolSys': file_gro_and_file_xtc_to_molsysmt_MolSys
}

from .to_molsysmt_Topology import molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_Topology
from .to_molsysmt_Topology import file_prmtop_and_file_inpcrd_to_molsysmt_Topology
from .to_molsysmt_Topology import file_psf_and_file_dcd_to_molsysmt_Topology
from .to_molsysmt_Topology import file_psf_and_file_crd_to_molsysmt_Topology
from .to_molsysmt_Topology import file_gro_and_file_xtc_to_molsysmt_Topology


_multiple_conversion_shortcuts[tuple(sorted(('molsysmt.Topology','molsysmt.Structures')))]={
'molsysmt.MolSys': molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_MolSys,
'molsysmt.Topology': molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_Topology
}

_multiple_conversion_shortcuts[tuple(sorted(('file:prmtop','file:inpcrd')))]={
'molsysmt.MolSys': file_prmtop_and_file_inpcrd_to_molsysmt_MolSys,
'molsysmt.Topology': file_prmtop_and_file_inpcrd_to_molsysmt_Topology
}

_multiple_conversion_shortcuts[tuple(sorted(('file:psf','file:dcd')))]={
'molsysmt.MolSys': file_psf_and_file_dcd_to_molsysmt_MolSys,
'molsysmt.Topology': file_psf_and_file_dcd_to_molsysmt_Topology
}

_multiple_conversion_shortcuts[tuple(sorted(('file:psf','file:crd')))]={
'molsysmt.MolSys': file_psf_and_file_crd_to_molsysmt_MolSys,
'molsysmt.Topology': file_psf_and_file_crd_to_molsysmt_Topology
}

_multiple_conversion_shortcuts[tuple(sorted(('file:gro','file:xtc')))]={
'molsysmt.MolSys': file_gro_and_file_xtc_to_molsysmt_MolSys,
'molsysmt.Topology': file_gro_and_file_xtc_to_molsysmt_Topology
}

10 changes: 9 additions & 1 deletion molsysmt/_private/digestion/argument/chain_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from ...exceptions import ArgumentError
from ...variables import is_all

functions_with_boolean = (
'molsysmt.basic.get.get',
'molsysmt.basic.compare.compare',
'molsysmt.basic.iterator.__init__',
'iterators.__init__',
)

set_functions = (
'set.set',
'set_chain_id_to_atom')
Expand Down Expand Up @@ -29,7 +36,8 @@ def digest_chain_id(chain_id, caller=None):
If the given `chain_id` has not of the correct type or value.
"""

if caller=='molsysmt.basic.get.get':

if caller.endswith(functions_with_boolean):
if isinstance(chain_id, bool):
return chain_id
elif caller.endswith(set_functions):
Expand Down
10 changes: 9 additions & 1 deletion molsysmt/_private/digestion/argument/chain_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
from ...variables import is_all
from numpy import ndarray

functions_with_boolean = (
'molsysmt.basic.get.get',
'molsysmt.basic.compare.compare',
'molsysmt.basic.iterator.__init__',
'iterators.__init__',
)


def digest_chain_name(chain_name, caller=None):
"""Checks if `chain_name` has the expected type and value.
Expand All @@ -26,7 +34,7 @@ def digest_chain_name(chain_name, caller=None):
If the given `chain_name` has not of the correct type or value.
"""

if caller=='molsysmt.basic.get.get':
if caller.endswith(functions_with_boolean):
if isinstance(chain_name, bool):
return chain_name
elif caller.startswith('molsysmt.form.') and caller.count('.to_')==2:
Expand Down
10 changes: 9 additions & 1 deletion molsysmt/_private/digestion/argument/chain_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
from ...variables import is_all
from numpy import ndarray

functions_with_boolean = (
'molsysmt.basic.get.get',
'molsysmt.basic.compare.compare',
'molsysmt.basic.iterator.__init__',
'iterators.__init__',
)


def digest_chain_type(chain_type, caller=None):
"""Checks if `chain_type` has the expected type and value.
Expand All @@ -26,7 +34,7 @@ def digest_chain_type(chain_type, caller=None):
If the given `chain_type` has not of the correct type or value.
"""

if caller=='molsysmt.basic.get.get':
if caller.endswith(functions_with_boolean):
if isinstance(chain_type, bool):
return chain_type
elif caller.startswith('molsysmt.form.') and caller.count('.to_')==2:
Expand Down
10 changes: 7 additions & 3 deletions molsysmt/_private/digestion/argument/keep_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

def digest_keep_ids(keep_ids, caller=None):

if isinstance(keep_ids, bool):
return keep_ids
if caller.endswith('.merge.merge'):
if isinstance(keep_ids, bool):
return keep_ids

raise ArgumentError('keep_ids', value=keep_ids, caller=caller, message=None)
if caller.endswith('.add.add'):
if isinstance(keep_ids, bool):
return keep_ids

raise ArgumentError('keep_ids', value=keep_ids, caller=caller, message=None)
2 changes: 1 addition & 1 deletion molsysmt/basic/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@digest()
def add(to_molecular_system, from_molecular_system, selection='all', structure_indices='all',
syntax='MolSysMT'):
keep_ids=True, syntax='MolSysMT'):
"""
Adding elements of a molecular system into another molecular system.
Expand Down
2 changes: 2 additions & 0 deletions molsysmt/basic/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
def merge(molecular_systems,
selections='all',
structure_indices='all',
keep_ids = True,
syntax='MolSysMT',
to_form=None,
skip_digestion=False
Expand Down Expand Up @@ -171,6 +172,7 @@ def merge(molecular_systems,
merge_arguments['structure_indices']=aux_structure_indices

merge_arguments['skip_digestion']=True
merge_arguments['keep_ids']=keep_ids

output = merge_function(aux_molecular_systems, **merge_arguments)

Expand Down
Binary file modified molsysmt/data/databases/amino_acids/A.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/C.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/D.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/G.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/H.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/I.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/L.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/M.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/N.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/O.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/P.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/S.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/T.pkl.gz
Binary file not shown.
Binary file modified molsysmt/data/databases/amino_acids/V.pkl.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions molsysmt/element/chain/get_chain_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def get_chain_type(molecular_system, element='atom', selection='all',
redefine_indices=redefine_molecule_indices,
redefine_types=redefine_molecule_types)

for ii in range(len(molecule_types_from_chain)):
if isinstance(molecule_types_from_chain[ii], str):
molecule_types_from_chain[ii]=[molecule_types_from_chain[ii]]

n_molecules = get_n_molecules(molecular_system, redefine_molecules=redefine_molecule_indices)

chain_types_from_chain = []
Expand Down
3 changes: 3 additions & 0 deletions molsysmt/element/group/amino_acid/get_bonded_atom_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_bonded_atom_pairs(group_name, atom_names, atom_indices=None, sorted=True
else:
return bonds


if group_name in ['HIS']:
for aux_group_name in group_names:
try:
Expand Down Expand Up @@ -75,6 +76,8 @@ def get_bonded_atom_pairs(group_name, atom_names, atom_indices=None, sorted=True
except:
pass

print(f'Warning! The amino acid {group_name} has no template.')
raise ValueError

return None

5 changes: 3 additions & 2 deletions molsysmt/form/molsysmt_MolSys/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import numpy as np

@digest(to_form='molsysmt.MolSys', from_form='molsysmt.MolSys')
def add(to_item, from_item, atom_indices='all', structure_indices='all', skip_digestion=False):
def add(to_item, from_item, atom_indices='all', structure_indices='all', keep_ids=True, skip_digestion=False):

to_item.add(from_item, atom_indices=atom_indices, structure_indices=structure_indices, skip_digestion=True)
to_item.add(from_item, atom_indices=atom_indices, structure_indices=structure_indices, keep_ids=keep_ids,
skip_digestion=True)

pass

4 changes: 2 additions & 2 deletions molsysmt/form/molsysmt_MolSys/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from molsysmt._private.variables import is_all

@digest(form='molsysmt.MolSys')
def merge(items, atom_indices='all', structure_indices='all', skip_digestion=False):
def merge(items, atom_indices='all', structure_indices='all', keep_ids=True, skip_digestion=False):

from molsysmt.native import MolSys
from ..molsysmt_Topology import merge as merge_molsysmt_Topology
Expand All @@ -26,7 +26,7 @@ def merge(items, atom_indices='all', structure_indices='all', skip_digestion=Fal

output = MolSys()
output.topology = merge_molsysmt_Topology([ii.topology for ii in items], atom_indices=atom_indices,
skip_digestion=True)
keep_ids=keep_ids, skip_digestion=True)
output.structures = merge_molsysmt_Structures([ii.structures for ii in items],
atom_indices=atom_indices, structure_indices=structure_indices, skip_digestion=True)
output.molecular_mechanics = merge_molsysmt_MolecularMechanics([ii.molecular_mechanics for ii in items],
Expand Down
Loading

0 comments on commit c29d492

Please sign in to comment.