Skip to content

Commit

Permalink
in process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Oct 5, 2023
1 parent b7b5d55 commit 51bb207
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 25 deletions.
7 changes: 5 additions & 2 deletions molsysmt/basic/remove.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from molsysmt._private.digestion import digest
from molsysmt._private.structure_indices import complementary_structure_indices
from molsysmt._private.atom_indices import complementary_atom_indices

from molsysmt._private.variables import is_all

@digest()
def remove(molecular_system, selection=None, structure_indices=None, to_form=None, syntax='MolSysMT'):
Expand Down Expand Up @@ -61,7 +61,7 @@ def remove(molecular_system, selection=None, structure_indices=None, to_form=Non
"""

from . import select, extract
from . import select, extract, get

atom_indices_to_be_kept = 'all'
structure_indices_to_be_kept = 'all'
Expand All @@ -71,6 +71,9 @@ def remove(molecular_system, selection=None, structure_indices=None, to_form=Non
atom_indices_to_be_kept = complementary_atom_indices(molecular_system, atom_indices_to_be_removed)

if structure_indices is not None:
if is_all(structure_indices):
n_structures = get(molecular_system, element='system', n_structures=True)
structure_indices= list(range(n_structures))
structure_indices_to_be_kept = complementary_structure_indices(molecular_system, structure_indices)

tmp_item = extract(molecular_system, selection=atom_indices_to_be_kept,
Expand Down
5 changes: 4 additions & 1 deletion molsysmt/element/atom/get_atom_type_from_atom_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ def get_atom_type_from_atom_name(atom_name):
To be written soon...
"""

return atom_type[atom[atom_name]]
try:
return atom_type[atom[atom_name]]
except:
raise ValueError('Atom name '+atom_name+' has not known atom type.')

41 changes: 28 additions & 13 deletions molsysmt/element/atom/names.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
atom={
'H' : 'atH' ,
'HN' : 'atH' , # charmm.pdb
'HN1' : 'atH' , #
'H1' : 'atH1' ,
'H2' : 'atH2' ,
'2HH' : 'atH2' , # pymol.pdb
Expand Down Expand Up @@ -78,22 +79,28 @@
'H8S' : 'atH8S' , # lipid POPC
'H8X' : 'atH8X' , # lipid POPC
'H8Y' : 'atH8Y' , # lipid POPC
'H9R' : 'atH9R' , # lipid POPC
'H9S' : 'atH9S' , # lipid POPC
'H9X' : 'atH9X' , # lipid POPC
'H9Y' : 'atH9Y' , # lipid POPC
'H10R' : 'atH10R' , # lipid POPC
'H10S' : 'atH10S' , # lipid POPC
'H10X' : 'atH10X' , # lipid POPC
'H10Y' : 'atH10Y' , # lipid POPC
'H11A' : 'atH11A' , # lipid POPC
'H11B' : 'atH11B' , # lipid POPC
'H11R' : 'atH11R' , # lipid POPC
'H11S' : 'atH11S' , # lipid POPC
'H11X' : 'atH11X' , # lipid POPC
'H11Y' : 'atH11Y' , # lipid POPC
'H11S' : 'atH11S' , # lipid POPC
'H12A' : 'atH12A' , # lipid POPC
'H12B' : 'atH12B' , # lipid POPC
'H12R' : 'atH12R' , # lipid POPC
'H12S' : 'atH12S' , # lipid POPC
'H12T' : 'atH12T' , # lipid POPC
'H12X' : 'atH12X' , # lipid POPC
'H12Y' : 'atH12Y' , # lipid POPC
'H12Z' : 'atH12Z' , # lipid POPC
'H13A' : 'atH13A' , # lipid POPC
'H13B' : 'atH13B' , # lipid POPC
'H13C' : 'atH13C' , # lipid POPC
Expand Down Expand Up @@ -228,6 +235,7 @@
'HH32' : 'atHH32' , # opls.gro
'3HH3' : 'atHH33' ,
'HH33' : 'atHH33' , # opls.gro
'HR' : 'atHR' , # lipid
'HS' : 'atHS' , # lipid POPC
'HNT' : 'atHT' , # ACEMD (NME Terminal)
'HX' : 'atHX' , # lipid POPC
Expand Down Expand Up @@ -500,35 +508,41 @@
'atH8S' : 'H' ,
'atH8X' : 'H' ,
'atH8Y' : 'H' ,
'atH9R' : 'H' ,
'atH9S' : 'H' ,
'atH9X' : 'H' ,
'atH9Y' : 'H' ,
'atH10R' : 'H' ,
'atH10S' : 'H' ,
'atH10X' : 'H' ,
'atH10Y' : 'H' ,
'atH11R' : 'H' ,
'atH11S' : 'H' ,
'atH11X' : 'H' ,
'atH11Y' : 'H' ,
'atH12S' : 'H' ,
'atH12R' : 'H' ,
'atH12T' : 'H' ,
'atH12X' : 'H' ,
'atH12Y' : 'H' ,
'atH12Z' : 'H' ,
'atH13R' : 'H' ,
'atH13S' : 'H' ,
'atH13X' : 'H' ,
'atH13Y' : 'H' ,
'atH14R' : 'H' ,
'atH14S' : 'H' ,
'atH14X' : 'H' ,
'atH14Y' : 'H' ,
'atH15R' : 'H' ,
'atH15S' : 'H' ,
'atH15X' : 'H' ,
'atH15Y' : 'H' ,
'atH16R' : 'H' ,
'atH16S' : 'H' ,
'atH16X' : 'H' ,
'atH16Y' : 'H' ,
'atH16Z' : 'H' ,
'atH11R' : 'H' ,
'atH11S' : 'H' ,
'atH12R' : 'H' ,
'atH12S' : 'H' ,
'atH13R' : 'H' ,
'atH13S' : 'H' ,
'atH14R' : 'H' ,
'atH14S' : 'H' ,
'atH15R' : 'H' ,
'atH15S' : 'H' ,
'atH16R' : 'H' ,
'atH16S' : 'H' ,
'atH17R' : 'H' ,
'atH17S' : 'H' ,
'atH18R' : 'H' ,
Expand Down Expand Up @@ -574,6 +588,7 @@
'atHH31': 'H' ,
'atHH32': 'H' ,
'atHH33': 'H' ,
'atHR' : 'H' ,
'atHS' : 'H' ,
'atHT' : 'H' ,
'atHT1' : 'H' ,
Expand Down
1 change: 1 addition & 0 deletions molsysmt/form/parmed_Structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .to_file_mol2 import to_file_mol2
from .to_file_pdb import to_file_pdb
from .to_file_psf import to_file_psf
from .to_file_cif import to_file_cif
from .to_mdtraj_Topology import to_mdtraj_Topology
from .to_mdtraj_Trajectory import to_mdtraj_Trajectory
from .to_nglview_NGLWidget import to_nglview_NGLWidget
Expand Down
41 changes: 40 additions & 1 deletion molsysmt/form/parmed_Structure/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

attributes = {ii:False for ii in _all_attributes}

attributes['atom_index'] = True
attributes['atom_index'] = True
attributes['atom_id'] = True
attributes['atom_name'] = True
Expand All @@ -23,8 +24,46 @@
attributes['chain_id'] = True
attributes['chain_name'] = True
attributes['chain_type'] = True
attributes['coordinates'] = True

attributes['n_atoms'] = True
attributes['n_groups'] = True
attributes['n_components'] = True
attributes['n_molecules'] = True
attributes['n_chains'] = True
attributes['n_entities'] = True
attributes['n_aminoacids'] = True
attributes['n_nucleotides'] = True
attributes['n_ions'] = True
attributes['n_waters'] = True
attributes['n_small_molecules'] = True
attributes['n_peptides'] = True
attributes['n_proteins'] = True
attributes['n_dnas'] = True
attributes['n_rnas'] = True
attributes['n_lipids'] = True
attributes['n_oligosaccharides'] = True
attributes['n_saccharides'] = True

attributes['bond_index'] = True
attributes['bond_id'] = False
attributes['bond_type'] = True
attributes['bond_order'] = True
attributes['bonded_atoms'] = True
attributes['inner_bond_index'] = True
attributes['inner_bonded_atoms'] = True
attributes['n_bonds'] = True
attributes['n_inner_bonds'] = True


attributes['structure_index'] = True
attributes['box'] = True
attributes['box_shape'] = True
attributes['box_angles'] = True
attributes['box_lengths'] = True
attributes['box_volume'] = True
attributes['coordinates'] = True
attributes['n_structures'] = True
attributes['b_factor'] = True


del(_all_attributes)
45 changes: 40 additions & 5 deletions molsysmt/form/parmed_Structure/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from molsysmt._private.execfile import execfile
from molsysmt._private.exceptions import NotImplementedMethodError, NotWithThisFormError
from molsysmt._private.digestion import digest
from molsysmt._private.variables import is_all

form='parmed.Structure'

Expand Down Expand Up @@ -63,7 +64,22 @@ def get_n_inner_bonds_from_atom(item, indices='all'):
@digest(form=form)
def get_coordinates_from_atom(item, indices='all', structure_indices='all'):

raise NotImplementedMethodError()
output = item.coordinates

if output is None:
return output

if not is_all(indices):
output = output[:,indices,:]
if not is_all(structure_indices):
output = output[structure_indices,:,:]

if not puw.is_quantity(output):
output = puw.quantity(output,'angstroms')

output = puw.standardize(output)

return output

## From group

Expand Down Expand Up @@ -191,22 +207,41 @@ def get_n_bonds_from_system(item):
@digest(form=form)
def get_n_structures_from_system(item, structure_indices='all'):

raise NotImplementedMethodError()
if is_all(structure_indices):
if item.coordinates is None:
return 0
else:
return item.coordinates.shape[0]
else:
return len(structure_indices)

@digest(form=form)
def get_box_from_system(item, structure_indices='all'):

raise NotImplementedMethodError()
output = item.box

if output is None:
return output

if not is_all(structure_indices):
output = output[structure_indices,:,:]

if not puw.is_quantity(output):
output = puw.quantity(output,'angstroms')

output = puw.standardize(output)

return output

@digest(form=form)
def get_time_from_system(item, structure_indices='all'):

raise NotImplementedMethodError()
return None

@digest(form=form)
def get_structure_id_from_system(item, structure_indices='all'):

raise NotImplementedMethodError()
return None

## From bond

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

@digest(form='parmed.Structure')
def to_file_cif(item, atom_indices='all', structure_indices='all', output_filename=None):

from . import extract

tmp_item = extract(item, atom_indices=atom_indices, structure_indices=structure_indices,
copy_if_all=False)
tmp_item.save(output_filename)
tmp_item = output_filename

return tmp_item

19 changes: 16 additions & 3 deletions molsysmt/form/parmed_Structure/to_molsysmt_Topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def to_molsysmt_Topology(item, atom_indices='all'):
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.element.atom import get_atom_type_from_atom_name
from ..molsysmt_Topology import extract

tmp_item = Topology()
Expand Down Expand Up @@ -33,25 +34,37 @@ def to_molsysmt_Topology(item, atom_indices='all'):

atom_index = 0

aux_dict_chains={}

for atom in item.atoms:

atom_index_array[atom_index] = atom._idx
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_type_array[atom_index] = get_atom_type_from_atom_name(atom.name)
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_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_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]
chain_index_array[atom_index] = chain_index
chain_id_array[atom_index] = chain_id

chain_index_array[atom_index] = 0
chain_id_array[atom_index] = None

atom_index+=1

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

tmp_item.atoms_dataframe["atom_index"] = atom_index_array
tmp_item.atoms_dataframe["atom_name"] = atom_name_array
Expand Down

0 comments on commit 51bb207

Please sign in to comment.