Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Feb 21, 2024
1 parent 6127b5e commit f878e5b
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
6 changes: 6 additions & 0 deletions molsysmt/form/parmed_Structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from .to_nglview_NGLWidget import to_nglview_NGLWidget
from .to_openmm_Modeller import to_openmm_Modeller
from .to_openmm_Topology import to_openmm_Topology
from .to_molsysmt_MolSys import to_molsysmt_MolSys
from .to_molsysmt_Topology import to_molsysmt_Topology
from .to_molsysmt_Structures import to_molsysmt_Structures
from .to_molsysmt_MolSysOld import to_molsysmt_MolSysOld
from .to_molsysmt_TopologyOld import to_molsysmt_TopologyOld
from .to_molsysmt_StructuresOld import to_molsysmt_StructuresOld
Expand All @@ -39,6 +42,9 @@
'nglview.NGLWidget': to_nglview_NGLWidget,
'openmm.Modeller': to_openmm_Modeller,
'openmm.Topology': to_openmm_Topology,
'molsysmt.MolSys': to_molsysmt_MolSys,
'molsysmt.Topology': to_molsysmt_Topology,
'molsysmt.Structures': to_molsysmt_Structures,
'molsysmt.MolSysOld': to_molsysmt_MolSysOld,
'molsysmt.TopologyOld': to_molsysmt_TopologyOld,
'molsysmt.StructuresOld': to_molsysmt_StructuresOld,
Expand Down
17 changes: 17 additions & 0 deletions molsysmt/form/parmed_Structure/to_molsysmt_MolSys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from molsysmt._private.digestion import digest

@digest(form='parmed.Structure')
def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_digestion=False):

from molsysmt.native.molsys import MolSys
from . import to_molsysmt_Topology
from . import to_molsysmt_Structures

tmp_item = MolSys()

tmp_item.topology = to_molsysmt_Topology(item, atom_indices=atom_indices, skip_digestion=True)
tmp_item.structures = to_molsysmt_Structures(item, atom_indices=atom_indices,
structure_indices=structure_indices, skip_digestion=True)

return tmp_item

21 changes: 21 additions & 0 deletions molsysmt/form/parmed_Structure/to_molsysmt_Structures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from molsysmt._private.digestion import digest

@digest(form='parmed.Structure')
def to_molsysmt_Structures(item, atom_indices='all', structure_indices='all', skip_digestion=False):

from molsysmt.native.structures import Structures
from . import get_coordinates_from_atom, get_structure_id_from_system, get_time_from_system, get_box_from_system

tmp_item = Structures()

coordinates = get_coordinates_from_atom(item, indices=atom_indices, structure_indices=structure_indices,
skip_digestion=True)
structure_id = get_structure_id_from_system(item, structure_indices=structure_indices, skip_digestion=True)
time = get_time_from_system(item, structure_indices=structure_indices, skip_digestion=True)
box = get_box_from_system(item, structure_indices=structure_indices, skip_digestion=True)

tmp_item.append(structure_id=structure_id, time=time, coordinates=coordinates, box=box,
skip_digestion=True)

return tmp_item

93 changes: 93 additions & 0 deletions molsysmt/form/parmed_Structure/to_molsysmt_Topology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from molsysmt._private.digestion import digest
import numpy as np
from molsysmt.element.group.get_group_type import _get_group_type_from_group_name
from molsysmt.element.atom.get_atom_type import _get_atom_type_from_atom_name

@digest(form='parmed.Structure')
def to_molsysmt_Topology(item, atom_indices='all', skip_digestion=False):

from molsysmt.native import Topology
from ..molsysmt_Topology import extract

tmp_item = Topology()

n_atoms = len(item.atoms)
n_groups = len(item.residues)
n_bonds = len(item.bonds)

tmp_item.reset_atoms(n_atoms=n_atoms)
tmp_item.reset_groups(n_groups=n_groups)
tmp_item.reset_bonds(n_bonds=n_bonds)

atom_index = 0
former_group_index = -1
former_chain_index = -1

aux_dict_chains={}

for atom in item.atoms:

group_index = atom.residue.idx

chain_id = atom.residue.chain
if chain_id not in aux_dict_chains:
aux_dict_chains[chain_id]=len(aux_dict_chains)
chain_index = aux_dict_chains[chain_id]


tmp_item.atoms.iloc[atom_index,0] = atom.idx
tmp_item.atoms.iloc[atom_index,1] = atom.name
tmp_item.atoms.iloc[atom_index,2] = _get_atom_type_from_atom_name(atom.name)
tmp_item.atoms.iloc[atom_index,3] = group_index
tmp_item.atoms.iloc[atom_index,4] = chain_index

if former_group_index!=group_index:
tmp_item.groups.iloc[group_index,0] = atom.residue.idx
tmp_item.groups.iloc[group_index,1] = atom.residue.name
tmp_item.groups.iloc[group_index,2] = _get_group_type_from_group_name(atom.residue.name)
former_group_index+=1

atom_index+=1

n_chains=len(aux_dict_chains)

tmp_item.reset_chains(n_chains=n_chains)

if len(aux_dict_chains)==1:
if '' in aux_dict_chains:
aux_dict_chains['A']=aux_dict_chains['']
del aux_dict_chains['']

for chain_id, chain_index in aux_dict_chains.items():
tmp_item.chains.iloc[chain_index,0] = chain_index
tmp_item.chains.iloc[chain_index,1] = chain_id

# bonds

bond_index = 0

for bond in item.bonds:

tmp_item.bonds.iloc[bond_index,0] = bond.atom1._idx
tmp_item.bonds.iloc[bond_index,1] = bond.atom2._idx

bond_index +=1

# components

tmp_item.rebuild_components()

## molecules

tmp_item.rebuild_molecules()

## entity

tmp_item.rebuild_entities()

## extract if atom_indices is not 'all'

tmp_item = extract(tmp_item, atom_indices=atom_indices, copy_if_all=False, skip_digestion=True)

return tmp_item

0 comments on commit f878e5b

Please sign in to comment.