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 7bcf8a2 commit 99c209a
Show file tree
Hide file tree
Showing 47 changed files with 914 additions and 1,466 deletions.
27 changes: 27 additions & 0 deletions molsysmt/_private/conversion_shortcuts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@
_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.Topology': molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_Topology
}

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

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

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

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

98 changes: 98 additions & 0 deletions molsysmt/_private/conversion_shortcuts/to_molsysmt_Topology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
def molsysmt_Topology_and_molsysmt_Structures_to_molsysmt_Topology(molecular_system, atom_indices='all',
structure_indices='all', skip_digestion=False):

from molsysmt.basic import get_form
from molsysmt.form.molsysmt_Topology import extract as extract_topology

forms = get_form(molecular_system)

topology = None

for form, item in zip(forms, molecular_system):
if form=='molsysmt.Topology':
topology = item
break

tmp_item = extract_topology(topology, atom_indices=atom_indices, copy_if_all=True, skip_digestion=True)

return tmp_item

def file_prmtop_and_file_inpcrd_to_molsysmt_Topology(molecular_system, atom_indices='all',
structure_indices='all', skip_digestion=False):

from molsysmt.basic import get_form
from molsysmt.form.file_prmtop import to_molsysmt_Topology as file_prmtop_to_molsysmt_Topology

forms = get_form(molecular_system)

item_prmtop = None

for form, item in zip(forms, molecular_system):
if form=='file:prmtop':
item_prmtop = item
break

tmp_item = file_prmtop_to_molsysmt_Topology(item_prmtop, atom_indices=atom_indices, skip_digestion=True)

return tmp_item

def file_psf_and_file_dcd_to_molsysmt_Topology(molecular_system, atom_indices='all', structure_indices='all',
skip_digestion=False):

from molsysmt.basic import get_form
from molsysmt.form.file_psf import to_molsysmt_Topology as file_psf_to_molsysmt_Topology
from molsysmt.native import MolSys

forms = get_form(molecular_system)

item_psf = None

for form, item in zip(forms, molecular_system):
if form=='file:psf':
item_psf = item
break

tmp_item = file_psf_to_molsysmt_Topology(item_psf, atom_indices=atom_indices, skip_digestion=True)

return tmp_item

def file_psf_and_file_crd_to_molsysmt_Topology(molecular_system, atom_indices='all', structure_indices='all',
skip_digestion=False):

from molsysmt.basic import get_form
from molsysmt.form.file_psf import to_molsysmt_Topology as file_psf_to_molsysmt_Topology

forms = get_form(molecular_system)

item_psf = None

for form, item in zip(forms, molecular_system):
if form=='file:psf':
item_psf = item
break

tmp_item = file_psf_to_molsysmt_Topology(item_psf, atom_indices=atom_indices, skip_digestion=True)

return tmp_item

def file_gro_and_file_xtc_to_molsysmt_Topology(molecular_system, atom_indices='all', structure_indices='all',
skip_digestion=False):

from molsysmt.basic import get_form
from molsysmt.form.file_gro import to_molsysmt_Topology as file_gro_to_molsysmt_Topology

forms = get_form(molecular_system)

item_gro = None

for form, item in zip(forms, molecular_system):
if form=='file:gro':
item_gro = item
break


tmp_item = file_gro_to_molsysmt_Topology(item_gro, atom_indices=atom_indices, get_missing_bonds=True,
skip_digestion=True)

return output_item

5 changes: 3 additions & 2 deletions molsysmt/basic/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def compare(molecular_system, molecular_system_2, selection='all', structure_ind
from molsysmt.basic import select, get, get_form, get_attributes
from molsysmt.form import _dict_modules
from molsysmt.attribute import attributes, _topological_attributes, _structural_attributes, _mechanical_attributes
from molsysmt.basic.get import _piped_molecular_system

output_dict = {}

Expand Down Expand Up @@ -201,8 +202,8 @@ def compare(molecular_system, molecular_system_2, selection='all', structure_ind

atts_required = set(atts_to_be_compared) & set(atts_of_A) & set(atts_of_B)

molecular_system = _piped_molecular_system(molecular_system, atts_required)
molecular_system_2 = _piped_molecular_system(molecular_system_2, atts_required)
molecular_system = _piped_molecular_system(molecular_system, 'atom', atts_required)
molecular_system_2 = _piped_molecular_system(molecular_system_2, 'atom', atts_required)

###### EQUAL #####

Expand Down
2 changes: 0 additions & 2 deletions molsysmt/basic/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def _convert_multiple_to_one_with_shortcuts(molecular_system,
sorted_forms = tuple(sorted(from_forms))

if to_form in _multiple_conversion_shortcuts[sorted_forms]:

function = _multiple_conversion_shortcuts[sorted_forms][to_form]

input_arguments = set(inspect.signature(function).parameters)
Expand All @@ -154,7 +153,6 @@ def _convert_multiple_to_one_with_shortcuts(molecular_system,
output = function(molecular_system, **conversion_arguments, **kwargs)

elif ('molsysmt.MolSys' in _multiple_conversion_shortcuts[sorted_forms]) and (to_form in _dict_modules['molsysmt.MolSys']._convert_to):

output = _convert_multiple_to_one_with_shortcuts(molecular_system, sorted_forms, to_form='molsysmt.MolSys', selection=selection,
structure_indices=structure_indices, syntax=syntax, **kwargs)
output = _convert_one_to_one(output, 'molsysmt.MolSys', to_form=to_form)
Expand Down
11 changes: 8 additions & 3 deletions molsysmt/basic/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get(molecular_system,
else:
indices = select(molecular_system, element=element, selection=mask, syntax=syntax, skip_digestion=True)

aux_molecular_system = _piped_molecular_system(molecular_system, in_attributes)
aux_molecular_system = _piped_molecular_system(molecular_system, element, in_attributes)

output = []

Expand Down Expand Up @@ -214,18 +214,23 @@ def get(molecular_system,
return dict(zip(in_attributes, output))


def _piped_molecular_system(molecular_system, in_attributes):
def _piped_molecular_system(molecular_system, element, in_attributes):

from .. import select, where_is_attribute, get_form, convert
from molsysmt.form import _dict_modules
from molsysmt.attribute import attributes, bonds_are_required_to_get_attribute
from molsysmt.attribute import is_topological_attribute, is_structural_attribute


piped_topological_attribute = {}
piped_structural_attribute = {}
piped_any_attribute = {}

form = get_form(molecular_system)

if not isinstance(molecular_system, (list, tuple)):
molecular_system = [molecular_system]
form = [form]

for aux_form in form:
piped_topological_attribute[aux_form] = getattr(_dict_modules[aux_form], f'piped_topological_attribute')
piped_structural_attribute[aux_form] = getattr(_dict_modules[aux_form], f'piped_structural_attribute')
Expand Down
41 changes: 0 additions & 41 deletions molsysmt/basic/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,36 +236,6 @@ def info(molecular_system,
if not attributes_filter['entity_index']: entity_index=None
if not attributes_filter['entity_name']: entity_name=None

if len(molecule_index.shape) > 1:
n_objects = molecule_index.shape[0]
aux_obj1_array = np.empty([n_objects], dtype='object')
aux_obj2_array = np.empty([n_objects], dtype='object')
for ii in range(n_objects):
aux_obj1_array[ii] = molecule_index[ii]
aux_obj2_array[ii] = molecule_type[ii]
molecule_index = aux_obj1_array
molecule_type = aux_obj2_array

for ii in range(len(molecule_index)):
if len(molecule_index[ii]) == 1:
molecule_index[ii] = molecule_index[ii][0]
molecule_type[ii] = molecule_type[ii][0]

if len(entity_index.shape) > 1:
n_objects = entity_index.shape[0]
aux_obj1_array = np.empty([n_objects], dtype='object')
aux_obj2_array = np.empty([n_objects], dtype='object')
for ii in range(n_objects):
aux_obj1_array[ii] = entity_index[ii]
aux_obj2_array[ii] = entity_name[ii]
entity_index = aux_obj1_array
entity_name = aux_obj2_array

for ii in range(len(entity_index)):
if len(entity_index[ii]) == 1:
entity_index[ii] = entity_index[ii][0]
entity_name[ii] = entity_name[ii][0]

return df({'index': chain_index, 'id': chain_id, 'name': chain_name,
'n atoms': n_atoms, 'n groups': n_groups, 'n components': n_components,
'molecule index': molecule_index, 'molecule type': molecule_type,
Expand All @@ -290,17 +260,6 @@ def info(molecular_system,
if not attributes_filter['entity_index']: entity_index=None
if not attributes_filter['entity_name']: entity_name=None

if len(chain_index.shape) > 1:
n_objects = chain_index.shape[0]
aux_obj_array = np.empty([n_objects], dtype='object')
for ii in range(n_objects):
aux_obj_array[ii] = chain_index[ii]
chain_index = aux_obj_array

for ii in range(len(chain_index)):
if len(chain_index[ii]) == 1:
chain_index[ii] = chain_index[ii][0]

return df({'index': molecule_index, 'name': molecule_name, 'type': molecule_type,
'n atoms': n_atoms, 'n groups': n_groups, 'n components': n_components,
'chain index': chain_index,
Expand Down
42 changes: 29 additions & 13 deletions molsysmt/basic/selector/molsysmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def select_standard(item, selection):

from molsysmt.basic import convert, get_form
from molsysmt.config import selection_shortcuts

from molsysmt.form import _dict_modules

tmp_selection = selection

Expand All @@ -59,17 +59,33 @@ def select_standard(item, selection):
tmp_item = item
else:

from molsysmt.attribute.bonds_are_required_to_get_attribute import bond_dependent_attributes
conversion_needs_missing_bonds=False

bonds_required_by_selection = False
for attribute in bond_dependent_attributes:
if attribute in tmp_selection:
bonds_required_by_selection = True
break
if isinstance(form_in, (list, tuple)):
for ii in form_in:
if (not _dict_modules[ii].bonds_are_explicit) and _dict_modules[ii].bonds_can_be_computed:
conversion_needs_missing_bonds=True
break
else:
if (not _dict_modules[form_in].bonds_are_explicit) and _dict_modules[form_in].bonds_can_be_computed:
conversion_needs_missing_bonds=True

if conversion_needs_missing_bonds:

from molsysmt.attribute.bonds_are_required_to_get_attribute import bond_dependent_attributes

tmp_item = convert(item, to_form='molsysmt.Topology', get_missing_bonds=bonds_required_by_selection,
skip_digestion=True)
bonds_required_by_selection = False
for attribute in bond_dependent_attributes:
if attribute in tmp_selection:
bonds_required_by_selection = True
break

tmp_item = convert(item, to_form='molsysmt.Topology', get_missing_bonds=bonds_required_by_selection,
skip_digestion=True)

else:

tmp_item = convert(item, to_form='molsysmt.Topology', skip_digestion=True)

if '@' in selection:

Expand Down Expand Up @@ -265,9 +281,9 @@ def select_within(molecular_system, selection, structure_indices):
structure_indices=structure_indices, threshold=threshold, pbc=pbc)

if not_within:
output = atom_indices_1[np.where(cmap.all(axis=2)[0] == False)[0]]
output = np.array(atom_indices_1)[np.where(cmap.all(axis=2)[0] == False)[0]].tolist()
else:
output = atom_indices_1[np.where(cmap.any(axis=2)[0] == True)[0]]
output = np.array(atom_indices_1)[np.where(cmap.any(axis=2)[0] == True)[0]].tolist()

return output

Expand All @@ -289,9 +305,9 @@ def select_bonded_to(molecular_system, selection):
atom_indices_2 = np.unique(np.concatenate(atom_indices_2).ravel())

if not_bonded:
output = np.setdiff1d(atom_indices_1, atom_indices_2, assume_unique=True)
output = np.setdiff1d(atom_indices_1, atom_indices_2, assume_unique=True).tolist()
else:
output = np.intersect1d(atom_indices_1, atom_indices_2, assume_unique=True)
output = np.intersect1d(atom_indices_1, atom_indices_2, assume_unique=True).tolist()

return output

Expand Down
10 changes: 5 additions & 5 deletions molsysmt/basic/selector/nglview.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def indices_to_selection(molecular_system, indices, element='atom'):
output_string = '@'+','.join([str(ii) for ii in indices])
elif element=='group':
from molsysmt import get
group_ids, chain_ids = get(molecular_system, element='group', selection=indices, group_id=True, chain_id=True)
if np.all(np.isin(np.unique(chain_ids), [' ', None])):
group_ids, chain_names = get(molecular_system, element='group', selection=indices, group_id=True, chain_name=True)
if np.all(np.isin(np.unique(chain_names), [' ', None])):
output_string = ','.join([str(ii) for ii in group_ids])
else:
output_string = ' '.join([str(ii)+':'+str(jj) for ii,jj in zip(group_ids, chain_ids)])
output_string = ' '.join([str(ii)+':'+str(jj) for ii,jj in zip(group_ids, chain_names)])
elif element=='chain':
from molsysmt import get
chain_ids = get(molecular_system, element='chain', selection=indices, chain_id=True)
output_string = ' '.join([':'+ii for ii in chain_ids])
chain_names = get(molecular_system, element='chain', selection=indices, chain_id=True)
output_string = ' '.join([':'+ii for ii in chain_names])
else:
raise NotImplementedMethodError

Expand Down
11 changes: 0 additions & 11 deletions molsysmt/data/databases/amino_acids/dat_to_pkl_gz.py

This file was deleted.

Loading

0 comments on commit 99c209a

Please sign in to comment.