Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Feb 16, 2024
1 parent 1bceac3 commit 7909946
Show file tree
Hide file tree
Showing 11 changed files with 63,183 additions and 228 deletions.
7 changes: 7 additions & 0 deletions molsysmt/form/file_gro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from .to_mdtraj_Trajectory import to_mdtraj_Trajectory
from .to_mdtraj_Topology import to_mdtraj_Topology
from .to_mdtraj_GroTrajectoryFile import to_mdtraj_GroTrajectoryFile
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 @@ -33,6 +36,9 @@
'mdtraj.Trajectory': to_mdtraj_Trajectory,
'mdtraj.Topology': to_mdtraj_Topology,
'mdtraj.GroTrajectoryFile': to_mdtraj_GroTrajectoryFile,
'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 All @@ -41,3 +47,4 @@
'openmm.GromacsGroFile': to_openmm_GromacsGroFile,
'nglview.NGLWidget': to_nglview_NGLWidget,
}

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

@digest(form='file:gro')
def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_digestion=False):

from . import to_mdtraj_Trajectory
from ..mdtraj_Trajectory import to_molsysmt_MolSys as mdtraj_Trajectory_to_molsysmt_MolSys

tmp_item = to_mdtraj_Trajectory(item, skip_digestion=True)
tmp_item = mdtraj_Trajectory_to_molsysmt_MolSys(tmp_item, atom_indices=atom_indices,
structure_indices=structure_indices, skip_digestion=True)

return tmp_item

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

@digest(form='file:gro')
def to_molsysmt_Structures(item, atom_indices='all', structure_indices='all', skip_digestion=False):

from . import to_openmm_GromacsGroFile
from ..openmm_GromacsGroFile import to_molsysmt_Structures as openmm_GromacsGroFile_to_molsysmt_Structures

tmp_item = to_openmm_GromacsGroFile(item, skip_digestion=True)
tmp_item = openmm_GromacsGroFile_to_molsysmt_Structures(tmp_item, atom_indices=atom_indices,
structure_indices=structure_indices,
skip_digestion=True)

return tmp_item

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

@digest(form='file:gro')
def to_molsysmt_Topology(item, atom_indices='all', skip_digestion=False):

#from . import to_mdtraj_Topology
#from ..mdtraj_Topology import to_molsysmt_Topology as mdtraj_Topology_to_molsysmt_Topology

#tmp_item = to_mdtraj_Topology(item, atom_indices=atom_indices, skip_digestion=True)
#tmp_item = mdtraj_Topology_to_molsysmt_Topology(tmp_item, skip_digestion=True)

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

tmp_item = Topology()

n_atoms = item.n_atoms
n_groups = item.n_residues
n_chains = item.n_chains
n_bonds = item.n_bonds


# atoms

atom_name_array = np.empty(n_atoms, dtype=object)
atom_id_array = np.empty(n_atoms, dtype=int)
atom_type_array = np.empty(n_atoms, dtype=object)
group_index_array = np.empty(n_atoms, dtype=int)
chain_index_array = np.empty(n_atoms, dtype=int)


return tmp_item

2 changes: 2 additions & 0 deletions molsysmt/form/mdtraj_Topology/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .to_mdtraj_Trajectory import to_mdtraj_Trajectory
from .to_parmed_Structure import to_parmed_Structure
from .to_parmed_GromacsTopologyFile import to_parmed_GromacsTopologyFile
from .to_molsysmt_Topology import to_molsysmt_Topology
from .to_molsysmt_TopologyOld import to_molsysmt_TopologyOld
from .to_openmm_Topology import to_openmm_Topology

Expand All @@ -33,6 +34,7 @@
'mdtraj_Trajectory': to_mdtraj_Trajectory,
'parmed_Structure': to_parmed_Structure,
'parmed_GromacsTopologyFile': to_parmed_GromacsTopologyFile,
'molsysmt_Topology': to_molsysmt_Topology,
'molsysmt_TopologyOld': to_molsysmt_TopologyOld,
'openmm_Topology': to_openmm_Topology,
}
135 changes: 135 additions & 0 deletions molsysmt/form/mdtraj_Topology/to_molsysmt_Topology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from molsysmt._private.digestion import digest
from molsysmt.element.group.get_group_type import _get_group_type_from_group_name

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

#from ..openmm_Topology import to_molsysmt_Topology as openmm_Topology_to_molsysmt_Topology

#tmp_item = item.to_openmm()
#tmp_item = openmm_Topology_to_molsysmt_Topology(tmp_item, atom_indices=atom_indices, skip_digestion=True)

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

tmp_item = Topology()

n_atoms = item.n_atoms
n_groups = item.n_residues
n_chains = item.n_chains
n_bonds = item.n_bonds

# atoms

atom_name_array = np.empty(n_atoms, dtype=object)
atom_id_array = np.empty(n_atoms, dtype=int)
atom_type_array = np.empty(n_atoms, dtype=object)
group_index_array = np.empty(n_atoms, dtype=int)
chain_index_array = np.empty(n_atoms, dtype=int)

for atom_index, atom in enumerate(item.atoms):

atom_name_array[atom_index] = atom.name
atom_id_array[atom_index] = atom.serial
atom_type_array[atom_index] = atom.element
group_index_array[atom_index] = atom.residue.index
chain_index_array[chain_index] = atom.residue.chain.index

tmp_item.atoms["atom_name"] = atom_name_array
tmp_item.atoms["atom_id"] = atom_id_array
tmp_item.atoms["atom_type"] = atom_type_array
tmp_item.atoms["group_index"] = group_index_array
tmp_item.atoms["chain_index"] = chain_index_array

del atom_name_array, atom_id_array, atom_type_array
del group_index_array, chain_index_array

# groups

group_name_array = np.empty(n_groups, dtype=object)
group_id_array = np.empty(n_groups, dtype=int)

aux_dict = {}

for group_index, residue in enumerate(item.residues):

group_name_array[group_index] = residue.name
group_id_array[group_index] = residue.resSeq

if residue.name not in aux_dict:
aux_dict[residue.name] = _get_group_type_from_group_name(residue.name)

tmp_item.groups["group_id"] = group_id_array
tmp_item.groups["group_name"] = group_name_array
tmp_item.groups["group_type"] = np.array([aux_dict[ii] for ii in group_name_array], dtype=object)

del group_name_array, group_id_array

# chains

chain_name_array = np.empty(n_chains, dtype=object)

index = 0

for chain in item.chains():

chain_name_array[index] = chain.chain_id

tmp_item.chains["chain_name"] = chain_name_array
tmp_item.chains["chain_id"] = tmp_item.chains.index

del chain_name_array

# bonds

bond_atom1_array = np.empty(n_bonds, dtype=int)
bond_atom2_array = np.empty(n_bonds, dtype=int)
bond_type_array = np.empty(n_bonds, dtype=object)
bond_order_array = np.empty(n_bonds, dtype=object)

for bond in item.bonds():

bond_atom1_array[index] = bond.atom1.index
bond_atom2_array[index] = bond.atom2.index
bond_order_array[index] = bond.order
bond_type_array[index] = bond.type

tmp_item.bonds["atom1_index"] = bond_atom1_array
tmp_item.bonds["atom2_index"] = bond_atom2_array
tmp_item.bonds["order"] = bond_order_array
tmp_item.bonds["type"] = bond_type_array

del bond_atom1_array, bond_atom2_array
del bond_order_array, bond_type_array

if tmp_item.bonds["order"].isnull().all():
tmp_item.bonds.drop("order", axis=1, inplace=True)

if tmp_item.bonds["type"].isnull().all():
tmp_item.bonds.drop("type", axis=1, inplace=True)

# components

tmp_item.rebuild_components()

# molecules

tmp_item.rebuild_molecules()

# chain types

tmp_item.rebuild_chain_types()

# entity

tmp_item.rebuild_entities()

# nan to None

tmp_item._fix_null_values()
tmp_item.bonds._sort_bonds()

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

return tmp_item

6 changes: 6 additions & 0 deletions molsysmt/form/mdtraj_Trajectory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from .to_openmm_Topology import to_openmm_Topology
from .to_openmm_Modeller import to_openmm_Modeller
from .to_pdbfixer_PDBFixer import to_pdbfixer_PDBFixer
from .to_molsysmt_MolSys import to_molsysmt_MolSys
from .to_molsysmt_Structures import to_molsysmt_Structures
from .to_molsysmt_Topology import to_molsysmt_Topology
from .to_molsysmt_MolSysOld import to_molsysmt_MolSysOld
from .to_molsysmt_StructuresOld import to_molsysmt_StructuresOld
from .to_molsysmt_TopologyOld import to_molsysmt_TopologyOld
Expand All @@ -44,6 +47,9 @@
'openmm.Topology': to_openmm_Topology,
'openmm.Modeller': to_openmm_Modeller,
'pdbfixer.PDBFixer': to_pdbfixer_PDBFixer,
'molsysmt.MolSys': to_molsysmt_MolSys,
'molsysmt.Structures': to_molsysmt_Structures,
'molsysmt.Topology': to_molsysmt_Topology,
'molsysmt.MolSysOld': to_molsysmt_MolSysOld,
'molsysmt.StructuresOld': to_molsysmt_StructuresOld,
'molsysmt.TopologyOld': to_molsysmt_TopologyOld,
Expand Down
17 changes: 17 additions & 0 deletions molsysmt/form/mdtraj_Trajectory/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='mdtraj.Trajectory')
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


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

@digest(form='mdtraj.Trajectory')
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_time_from_system, get_structure_id_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)
time = get_time_from_system(item, structure_indices=structure_indices, skip_digestion=True)
structure_id = get_structure_id_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, box=box, coordinates=coordinates)

return tmp_item

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

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

from . import to_mdtraj_Topology
from ..mdtraj_Topology import to_molsysmt_Topology as mdtraj_Topology_to_molsysmt_Topology

tmp_item = to_mdtraj_Topology(item, skip_digestion=True)
tmp_item = mdtraj_Topology_to_molsysmt_Topology(tmp_item, atom_indices=atom_indices, skip_digestion=True)

return tmp_item

Loading

0 comments on commit 7909946

Please sign in to comment.