From b7b5d5557f3fef6cf5ed5950783a2dca1af7cf26 Mon Sep 17 00:00:00 2001 From: Diego Prada Date: Wed, 4 Oct 2023 17:48:21 -0600 Subject: [PATCH] in process --- .../openmm_Topology/to_molsysmt_Topology.py | 1 - .../parmed_Structure/to_molsysmt_Topology.py | 116 +++++++++++++++++- .../parmed_Structure/to_openmm_Topology.py | 2 +- 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/molsysmt/form/openmm_Topology/to_molsysmt_Topology.py b/molsysmt/form/openmm_Topology/to_molsysmt_Topology.py index c45b5274a..67293527a 100644 --- a/molsysmt/form/openmm_Topology/to_molsysmt_Topology.py +++ b/molsysmt/form/openmm_Topology/to_molsysmt_Topology.py @@ -18,7 +18,6 @@ def to_molsysmt_Topology(item, atom_indices='all'): atom_name_array = empty(n_atoms, dtype=object) atom_id_array = empty(n_atoms, dtype=int) atom_type_array = empty(n_atoms, dtype=object) - atom_bonded_atom_indices_array = empty(n_atoms, dtype=object) group_index_array = empty(n_atoms, dtype=int) group_name_array = empty(n_atoms, dtype=object) diff --git a/molsysmt/form/parmed_Structure/to_molsysmt_Topology.py b/molsysmt/form/parmed_Structure/to_molsysmt_Topology.py index a878ccad5..3398484ed 100644 --- a/molsysmt/form/parmed_Structure/to_molsysmt_Topology.py +++ b/molsysmt/form/parmed_Structure/to_molsysmt_Topology.py @@ -3,11 +3,119 @@ @digest(form='parmed.Structure') def to_molsysmt_Topology(item, atom_indices='all'): - from . import to_openmm_Topology - from ..openmm_Topology import to_molsysmt_Topology + from molsysmt.native import Topology + from numpy import empty, array, arange, reshape, where, unique, nan, sort, zeros + from molsysmt.element.group import get_group_type_from_group_name + from ..molsysmt_Topology import extract - tmp_item = to_openmm_Topology(item) - tmp_item = openmm_Topology_to_molsysmt_Topology(tmp_item, atom_indices=atom_indices) + tmp_item = Topology() + + n_atoms = len(item.atoms) + + # atoms, groups and chains + + atom_index_array = empty(n_atoms, dtype=int) + atom_name_array = empty(n_atoms, dtype=object) + atom_id_array = empty(n_atoms, dtype=int) + atom_type_array = empty(n_atoms, dtype=object) + atom_partial_charge_array = empty(n_atoms, dtype=object) + atom_formal_charge_array = empty(n_atoms, dtype=object) + + group_index_array = empty(n_atoms, dtype=int) + group_name_array = empty(n_atoms, dtype=object) + group_id_array = empty(n_atoms, dtype=int) + group_type_array = empty(n_atoms, dtype=object) + + chain_index_array = empty(n_atoms, dtype=int) + chain_name_array = empty(n_atoms, dtype=object) + chain_id_array = empty(n_atoms, dtype=object) + chain_type_array = empty(n_atoms, dtype=object) + + atom_index = 0 + + for atom in item.atoms: + + atom_index_array[atom_index] = atom._idx + atom_name_array[atom_index] = atom.name + atom_id_array[atom_index] = atom.idx + atom_type_array[atom_index] = None + atom_partial_charge_array[atom_index] = atom.charge + atom_formal_charge_array[atom_index] = atom.formal_charge + + group_index_array[atom_index] = atom.residue._idx + group_name_array[atom_index] = atom.residue.name + group_id_array[atom_index] = atom.residue.idx + group_type_array[atom_index] = get_group_type_from_group_name(atom.residue.name) + + chain_index_array[atom_index] = 0 + chain_id_array[atom_index] = None + + atom_index+=1 + + + tmp_item.atoms_dataframe["atom_index"] = atom_index_array + tmp_item.atoms_dataframe["atom_name"] = atom_name_array + tmp_item.atoms_dataframe["atom_id"] = atom_id_array + tmp_item.atoms_dataframe["atom_type"] = atom_type_array + tmp_item.atoms_dataframe["formal_charge"] = atom_formal_charge_array + tmp_item.atoms_dataframe["partial_charge"] = atom_partial_charge_array + del(atom_index_array, atom_name_array, atom_id_array, atom_type_array) + del(atom_formal_charge_array, atom_partial_charge_array) + + tmp_item.atoms_dataframe["group_index"] = group_index_array + tmp_item.atoms_dataframe["group_name"] = group_name_array + tmp_item.atoms_dataframe["group_id"] = group_id_array + tmp_item.atoms_dataframe["group_type"] = group_type_array + del(group_index_array, group_id_array, group_name_array, group_type_array) + + tmp_item.atoms_dataframe["chain_index"] = chain_index_array + tmp_item.atoms_dataframe["chain_id"] = chain_id_array + del(chain_index_array, chain_id_array, chain_name_array, chain_type_array) + + # bonds + + n_bonds = len(item.bonds) + + bond_atom1_array = empty(n_bonds, dtype=int) + bond_atom2_array = empty(n_bonds, dtype=int) + bond_type_array = empty(n_bonds, dtype=object) + bond_order_array = empty(n_bonds, dtype=object) + + bond_index = 0 + + for bond in item.bonds: + + bond_atom1_array[bond_index] = bond.atom1._idx + bond_atom2_array[bond_index] = bond.atom2._idx + bond_order_array[bond_index] = bond.order + bond_type_array[bond_index] = bond.type + + bond_index +=1 + + tmp_item.bonds_dataframe["atom1_index"] = bond_atom1_array + tmp_item.bonds_dataframe["atom2_index"] = bond_atom2_array + tmp_item.bonds_dataframe["order"] = bond_order_array + tmp_item.bonds_dataframe["type"] = bond_type_array + + # components + + tmp_item._build_components() + + ## molecules + + tmp_item._build_molecules() + + ## entity + + tmp_item._build_entities() + + ## nan to None + + tmp_item._nan_to_None() + + ## extract if atom_indices is not 'all' + + tmp_item = extract(tmp_item, atom_indices=atom_indices, copy_if_all=False) return tmp_item diff --git a/molsysmt/form/parmed_Structure/to_openmm_Topology.py b/molsysmt/form/parmed_Structure/to_openmm_Topology.py index 103d43f6c..29c925d9a 100644 --- a/molsysmt/form/parmed_Structure/to_openmm_Topology.py +++ b/molsysmt/form/parmed_Structure/to_openmm_Topology.py @@ -5,7 +5,7 @@ def to_openmm_Topology(item, atom_indices='all'): from ..openmm_Topology import extract as extract_openmm_Topology - tmp_item = tmp_item.topology + tmp_item = item.topology tmp_item = extract_openmm_Topology(tmp_item, atom_indices=atom_indices, copy_if_all=False) return tmp_item