Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed May 19, 2024
1 parent e409d1e commit 5320af2
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 90 deletions.
183 changes: 138 additions & 45 deletions docs/contents/user/tools/basic/convert.ipynb

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions molsysmt/basic/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,18 @@ def _piped_molecular_system(molecular_system, element, in_attributes):
skip_digestion=True)
if is_topological_attribute(in_attribute, skip_digestion=True):
_, aux_form = where_is_attribute(molecular_system, in_attribute, skip_digestion=True)
if piped_topological_attribute[aux_form] not in aux_piped_topological_attribute:
aux_piped_topological_attribute.append(piped_topological_attribute[aux_form])
if piped_any_attribute[aux_form] not in aux_piped_any_attribute:
aux_piped_any_attribute.append(piped_any_attribute[aux_form])
if aux_form is not None:
if piped_topological_attribute[aux_form] not in aux_piped_topological_attribute:
aux_piped_topological_attribute.append(piped_topological_attribute[aux_form])
if piped_any_attribute[aux_form] not in aux_piped_any_attribute:
aux_piped_any_attribute.append(piped_any_attribute[aux_form])
elif is_structural_attribute(in_attribute, skip_digestion=True):
_, aux_form = where_is_attribute(molecular_system, in_attribute)
if piped_structural_attribute[aux_form] not in aux_piped_structural_attribute:
aux_piped_structural_attribute.append(piped_structural_attribute[aux_form])
if piped_any_attribute[aux_form] not in aux_piped_any_attribute:
aux_piped_any_attribute.append(piped_any_attribute[aux_form])
if aux_form is not None:
if piped_structural_attribute[aux_form] not in aux_piped_structural_attribute:
aux_piped_structural_attribute.append(piped_structural_attribute[aux_form])
if piped_any_attribute[aux_form] not in aux_piped_any_attribute:
aux_piped_any_attribute.append(piped_any_attribute[aux_form])

n_top = len(aux_piped_topological_attribute)
n_str = len(aux_piped_structural_attribute)
Expand Down
48 changes: 25 additions & 23 deletions molsysmt/element/component/get_component_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all
import numpy as np

import pandas as pd

@digest()
def get_component_type(molecular_system, element='atom', selection='all', redefine_indices=False,
Expand All @@ -15,45 +16,43 @@ def get_component_type(molecular_system, element='atom', selection='all', redefi

if redefine_indices:

atom_indices = select(molecular_system, element='atom', selection=selection,
syntax=syntax, skip_digestion=True)

#if element!='atom':
# aux_atom_indices = []
# for aux in atom_indices:
# aux_atom_indices += aux
# atom_indices = aux_atom_indices

component_indices = get_component_index(molecular_system, element='atom',
selection='all', redefine_indices=True,
skip_digestion=True)

unique_component_indices, first_atoms, n_atoms = np.unique(component_indices, return_index=True,
return_counts=True)
group_index_per_atom = get(molecular_system, element='atom', selection='all', group_index=True,
skip_digestion=True)

component_types={}
group_names, group_types = get(molecular_system, element='group', selection='all', group_name=True,
group_type=True, skip_digestion=True)

for component_index, first_atom, aux_n_atoms in zip(unique_component_indices, first_atoms, n_atoms):
group_names = np.array(group_names)
group_types = np.array(group_types)


aux_df = pd.DataFrame({'component_indices':component_indices, 'group_indices':group_index_per_atom})
aux_dict = aux_df.groupby('component_indices')['group_indices'].unique().to_dict()

component_types={}

atom_indices_component = list(np.arange(aux_n_atoms))+first_atom
aux_group_names, aux_group_types = get(molecular_system, element='group',
selection='atom_index in @atom_indices_component',
group_name=True, group_type=True,
syntax='MolSysMT', skip_digestion=True)
for component_index, group_indices in aux_dict.items():

component_type = _get_component_type_from_group_names_and_types(aux_group_names, aux_group_types)
component_type = _get_component_type_from_group_names_and_types(group_names[group_indices],
group_types[group_indices])

component_types[component_index]=component_type

if element == 'atom':

atom_indices = select(molecular_system, element='atom', selection=selection,
syntax=syntax, skip_digestion=True)
output = [component_types[component_indices[ii]] for ii in atom_indices]

elif element == 'group':

output = []
group_indices = get(molecular_system, element='atom',
selection=atom_indices, group_indices=True, skip_digestion=True)
selection=selection, group_indices=True, skip_digestion=True)
former_index = -1
for ii,jj,kk in zip(group_indices, atom_indices, component_indices):
if ii!=former_index:
Expand All @@ -63,13 +62,16 @@ def get_component_type(molecular_system, element='atom', selection='all', redefi

elif element == 'component':

output = list(component_types.values())
if is_all(selection):
output = list(component_types.values())
else:
raise NotImplementedError

else:

raise NotImplementedError

del atom_indices, component_types, component_indices
del component_types, component_indices, group_index_per_atom, group_names, group_types

else:

Expand Down
2 changes: 1 addition & 1 deletion molsysmt/element/molecule/get_molecule_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@digest()
def get_molecule_name(molecular_system, element='atom', selection='all', redefine_molecules=False,
redefine_names=False, syntax='MolSysMT'):
redefine_names=False, syntax='MolSysMT', skip_digestion=False):

if redefine_molecules or redefine_names:

Expand Down
2 changes: 0 additions & 2 deletions molsysmt/element/molecule/get_molecule_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ def get_molecule_type(molecular_system, element='atom', selection='all',

if redefine_indices:

print('da1')
molecule_types_from_molecule = get_component_type(molecular_system, element='component', selection=selection,
redefine_indices=True, syntax=syntax)
print('da2')

if element == 'atom':
aux = get(molecular_system, element='atom', selection=selection, syntax=syntax,
Expand Down
4 changes: 3 additions & 1 deletion molsysmt/form/file_prmtop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
form_info = ["AMBER parameter/topology file format",
"https://ambermd.org/FileFormats.php#topology"]

piped_topological_attribute = None
piped_topological_attribute = 'molsysmt.Topology'
piped_structural_attribute = None
piped_any_attribute = None
bonds_are_explicit = True
bonds_can_be_computed = False

from .is_form import is_form

Expand Down
1 change: 1 addition & 0 deletions molsysmt/form/file_prmtop/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
attributes['n_lipids'] = True
attributes['n_oligosaccharides'] = True
attributes['n_saccharides'] = True
attributes['n_entities'] = True

attributes['bond_index'] = True
attributes['bond_id'] = True
Expand Down
11 changes: 1 addition & 10 deletions molsysmt/form/file_prmtop/to_molsysmt_MolSys.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
from molsysmt._private.digestion import digest

@digest(form='file:prmtop')
def to_molsysmt_MolSys(item, atom_indices='all',
component_id=None, component_type=None, component_name=None,
entity_id=None, entity_type=None, entity_name=None,
structure_id=None, coordinates=None, velocities=None, time=None, box=None,
formal_charge=None, partial_charge=None, forcefield=None, non_bonded_method=None,
cutoff_distance=None, switch_distance=None, dispersion_correction=None, ewald_error_tolerance=None,
hydrogen_mass=None, constraints=None, flexible_constraints=None, water_model=None, rigid_water=None,
implicit_solvent=None, solute_dielectric=None, solvent_dielectric=None, salt_concentration=None,
kappa=None):
def to_molsysmt_MolSys(item, atom_indices='all', skip_digestion=False):

from molsysmt.native import MolSys, Structures
from .to_molsysmt_Topology import to_molsysmt_Topology
tmp_item = MolSys()
tmp_item.topology = to_molsysmt_Topology(item, atom_indices=atom_indices)
tmp_item.structures = Structures()
tmp_item.structures.append_structures(coordinates=coordinates)

return tmp_item

0 comments on commit 5320af2

Please sign in to comment.