Skip to content

Commit

Permalink
In process
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Apr 1, 2024
1 parent 8f8d8e1 commit ca64a98
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 44 deletions.
12 changes: 8 additions & 4 deletions molsysmt/data/_make/chicken_villin_HP35.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
'mmtf/1vii.mmtf',
'h5msm/chicken_villin_HP35.h5msm',
'h5msm/chicken_villin_HP35_solvated.h5msm',
'dcd/traj_chicken_villin_HP35_solvated.dcd',
'h5/traj_chicken_villin_HP35_solvated.h5',
'dcd/traj_chicken_villin_HP35.dcd',
'h5/traj_chicken_villin_HP35.h5',
'h5msm/traj_chicken_villin_HP35.h5msm',
]

for filename in files_to_be_purged:
filepath = Path(data_dir, filename)
if os.path.isfile(filepath):
os.remove(filepath)


# Make

# 1vii pdb and mmtf files
Expand Down Expand Up @@ -53,11 +55,10 @@
molsys = msm.build.solvate([molsys, {'forcefield':'AMBER14', 'water_model':'TIP3P'}],
box_shape='truncated octahedral', clearance='14.0 angstroms',
to_form='molsysmt.MolSys')
_ = msm.convert(molsys, to_form='chicken_villin_HP35_solvated.msmpk')
_ = msm.convert(molsys, to_form='chicken_villin_HP35_solvated.h5msm')
shutil.move('chicken_villin_HP35_solvated.h5msm', Path(data_dir, 'h5msm/chicken_villin_HP35_solvated.h5msm'))



# simulation
print('Trajectory files...')
modeller = msm.convert(molsys, to_form='openmm.Modeller')
Expand All @@ -73,10 +74,13 @@
potentialEnergy=True, temperature=True, remainingTime=True, totalSteps=1000000))
simulation.reporters.append(app.DCDReporter('traj_chicken_villin_HP35_solvated.dcd', 50000, enforcePeriodicBox=True))
simulation.reporters.append(HDF5Reporter('traj_chicken_villin_HP35_solvated.h5', 50000))
#simulation.reporters.append(msm.thirds.openmm.reporters.H5MSMReporter('traj_chicken_villin_HP35_solvated.h5msm',
# 10000000, 50000))
simulation.step(1000000)
simulation.reporters[2].close()
final_positions = simulation.context.getState(getPositions=True).getPositions()

shutil.move('traj_chicken_villin_HP35_solvated.dcd', Path(data_dir, 'dcd/traj_chicken_villin_HP35_solvated.dcd'))
shutil.move('traj_chicken_villin_HP35_solvated.h5', Path(data_dir, 'h5/traj_chicken_villin_HP35_solvated.h5'))
#shutil.move('traj_chicken_villin_HP35_solvated.h5msm', Path(data_dir, 'h5/traj_chicken_villin_HP35_solvated.h5msm'))

Binary file not shown.
Binary file not shown.
Binary file modified molsysmt/data/dcd/traj_chicken_villin_HP35_solvated.dcd
Binary file not shown.
Binary file modified molsysmt/data/h5/traj_chicken_villin_HP35_solvated.h5
Binary file not shown.
Binary file added molsysmt/data/h5msm/chicken_villin_HP35.h5msm
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions molsysmt/form/molsysmt_MolSys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .to_molsysmt_MolecularMechanicsDict import to_molsysmt_MolecularMechanicsDict
from .to_networkx_Graph import to_networkx_Graph
from .to_nglview_NGLWidget import to_nglview_NGLWidget
from .to_openmm_Context import to_openmm_Context
from .to_openmm_Topology import to_openmm_Topology
from .to_openmm_Modeller import to_openmm_Modeller
from .to_pdbfixer_PDBFixer import to_pdbfixer_PDBFixer
Expand All @@ -40,6 +41,7 @@
'molsysmt.MolecularMechanicsDict': to_molsysmt_MolecularMechanicsDict,
'networkx.Graph': to_networkx_Graph,
'nglview.NGLWidget': to_nglview_NGLWidget,
'openmm.Context': to_openmm_Context,
'openmm.Topology': to_openmm_Topology,
'openmm.Modeller': to_openmm_Modeller,
'pdbfixer.PDBFixer': to_pdbfixer_PDBFixer,
Expand Down
26 changes: 26 additions & 0 deletions molsysmt/form/molsysmt_MolSys/to_openmm_Context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from molsysmt._private.digestion import digest

@digest(form='molsysmt.MolSys')
def to_openmm_Context(item, atom_indices='all', structure_indices='all',
forcefield='AMBER14', water_model=None, implicit_solvent=None,
non_bonded_method='no cutoff', constraints='hbonds', switch_distance=None,
dispersion_correction=False, ewald_error_tolerance=0.0005,
integrator='Langevin', temperature='300.0 kelvin', friction='1.0/picoseconds', time_step='2 femtoseconds',
platform='CUDA', skip_digestion=False):

from . import to_openmm_Topology
from . import get_coordinates_from_atom
from ..openmm_Topology import to_openmm_Context as openmm_Topology_to_openmm_Context

tmp_item = to_openmm_Topology(item, atom_indices=atom_indices, structure_indices=structure_indices, skip_digestion=True)
coordinates = get_coordinates_from_atom(item, indices=atom_indices, structure_indices=structure_indices, skip_digestion=True)

tmp_item = openmm_Topology_to_openmm_Context(tmp_item, coordinates=coordinates,
forcefield=forcefield, water_model=water_model, implicit_solvent=implicit_solvent,
non_bonded_method=non_bonded_method, constraints=constraints, switch_distance=switch_distance,
dispersion_correction=dispersion_correction, ewald_error_tolerance=ewald_error_tolerance,
integrator=integrator, temperature=temperature, friction=friction, time_step=time_step,
platform=platform, skip_digestion=True)

return tmp_item

10 changes: 9 additions & 1 deletion molsysmt/form/molsysmt_Topology/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
from .set import *
from .iterators import TopologyIterator

from .to_file_h5msm import to_file_h5msm
from .to_string_aminoacids3 import to_string_aminoacids3
from .to_string_aminoacids1 import to_string_aminoacids1
from .to_string_pdb_text import to_string_pdb_text
from .to_file_h5msm import to_file_h5msm, dump_topology_to_h5msm
from .to_networkx_Graph import to_networkx_Graph
from .to_openmm_Topology import to_openmm_Topology
from .to_parmed_Structure import to_parmed_Structure

_convert_to={
'molsysmt.Topology': extract,
'string:aminoacids1': to_string_aminoacids1,
'string:aminoacids3': to_string_aminoacids3,
'string:pdb_text': to_string_pdb_text,
'file:h5msm': to_file_h5msm,
'networkx.Graph': to_networkx_Graph,
'openmm.Topology': to_openmm_Topology,
'parmed.Structure': to_parmed_Structure,
}
2 changes: 1 addition & 1 deletion molsysmt/form/molsysmt_Topology/to_file_h5msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def to_file_h5msm(item, atom_indices='all', coordinates=None, output_filename=No

return output_filename

def _add_topology_to_h5msm(item, file, atom_indices='all'):
def dump_topology_to_h5msm(item, file, atom_indices='all'):

from h5py._hl.files import File as h5py_File
from molsysmt.native import H5MSMFileHandler
Expand Down
12 changes: 12 additions & 0 deletions molsysmt/form/molsysmt_Topology/to_parmed_Structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from molsysmt._private.digestion import digest

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

from .to_openmm_Topology import to_openmm_Topology as molsysmt_Topology_to_openmm_Topology
from ..openmm_Topology import to_parmed_Structure as openmm_Topology_to_parmed_Structure

tmp_item = molsysmt_Topology_to_openmm_Topology(item, atom_indices=atom_indices)
tmp_item = openmm_Topology_to_parmed_Structure(tmp_item)
return tmp_item

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

@digest(form='molsysmt.Topology')
def to_string_aminoacids1(item, group_indices='all', skip_digestion=False):

from . import to_string_aminoacids3
from ..string_aminoacids3 import to_string_aminoacids1 as string_aminoacids3_to_string_aminoacids1

tmp_item = to_string_aminoacids3(item, group_indices=group_indices)
tmp_item = string_aminoacids3_to_string_aminoacids1(tmp_item)

return tmp_item

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

@digest(form='molsysmt.Topology')
def to_string_aminoacids3(item, group_indices='all', skip_digestion=False):

from . import get_group_name_from_group

group_names = get_group_name_from_group(item, indices=group_indices)
tmp_item = ''.join([ii.title() for ii in group_names])

return tmp_item

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

@digest(form='molsysmt.Topology')
def to_string_pdb_text(item, atom_indices='all', coordinates=None, box=None, skip_digestion=False):

from molsysmt.native import MolSys, Structures
from . import extract
from ..molsysmt_MolSys import to_string_pdb_text as molsysmt_MolSys_to_string_pdb_text

tmp_item = MolSys()
tmp_item.topology = extract(item, atom_indices=atom_indices, copy_if_all=False, skip_digestion=True)
tmp_item.structures.append(coordinates=coordinates, box=box, skip_digestion=True)
tmp_item = molsysmt_MolSys_to_string_pdb_text(tmp_item, skip_digestion=True)

return tmp_item


6 changes: 3 additions & 3 deletions molsysmt/form/openmm_Topology/to_openmm_Context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def to_openmm_Context(item, atom_indices='all', coordinates=None, forcefield='AMBER14', water_model=None,
implicit_solvent=None, non_bonded_method='no cutoff', constraints='hbonds', switch_distance=None,
dispersion_correction=False, ewald_error_tolerance=0.0005, integrator='Langevin', temperature=None,
friction='1.0/picoseconds', time_step='2 femtoseconds', platform='CUDA'):
friction='1.0/picoseconds', time_step='2 femtoseconds', platform='CUDA', skip_digestion=False):


from . import to_openmm_System
Expand All @@ -14,10 +14,10 @@ def to_openmm_Context(item, atom_indices='all', coordinates=None, forcefield='AM
water_model=water_model, implicit_solvent=implicit_solvent,
non_bonded_method=non_bonded_method, constraints=constraints,
switch_distance=switch_distance, dispersion_correction=dispersion_correction,
ewald_error_tolerance=ewald_error_tolerance)
ewald_error_tolerance=ewald_error_tolerance, skip_digestion=True)
context = openmm_System_to_openmm_Context(system, coordinates=coordinates,
integrator=integrator, temperature=temperature, friction=friction,
time_step=time_step, platform=platform)
time_step=time_step, platform=platform, skip_digestion=True)

return context

2 changes: 1 addition & 1 deletion molsysmt/molecular_mechanics/forcefields.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
}


def forcefield_to_engine(forcefield, implicit_solvent=None, water_model=None, engine='OpenMM'):
def forcefield_to_engine(forcefield, implicit_solvent=None, water_model=None, engine='OpenMM', skip_digestion=False):

forcefield_out = None

Expand Down
4 changes: 2 additions & 2 deletions molsysmt/native/h5msm_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def write_topology(self, topology, selection='all', syntax='MolSysMT'):

try:
topology_form = get_form(topology)
_dict_modules[topology_form].write_topology_in_h5msm(topology, file=self.file,
_dict_modules[topology_form].dump_topology_to_h5msm(topology, file=self.file,
atom_indices=atom_indices)
except:
aux_topology = convert(topology, to_form='molsysmt.Topology', selection=atom_indices)
_dict_modules['molsysmt.Topology'].write_topology_in_h5msm(aux_topology, file=self.file,
_dict_modules['molsysmt.Topology'].dump_topology_to_h5msm(aux_topology, file=self.file,
atom_indices=atom_indices)
del(aux_topology)

Expand Down
14 changes: 7 additions & 7 deletions molsysmt/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def path(package, file):

# Villin HP35

#systems['chicken villin HP35'] = {}
#systems['chicken villin HP35']['1vii.pdb'] = path('molsysmt.data.pdb', '1vii.pdb')
#systems['chicken villin HP35']['1vii.mmtf'] = path('molsysmt.data.mmtf', '1vii.mmtf')
#systems['chicken villin HP35']['chicken_villin_HP35.msmpk'] = path('molsysmt.data.msmpk', 'chicken_villin_HP35.msmpk')
#systems['chicken villin HP35']['chicken_villin_HP35_solvated.msmpk'] = path('molsysmt.data.msmpk', 'chicken_villin_HP35_solvated.msmpk')
#systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.dcd'] = path('molsysmt.data.dcd', 'traj_chicken_villin_HP35_solvated.dcd')
#systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5'] = path('molsysmt.data.h5', 'traj_chicken_villin_HP35_solvated.h5')
systems['chicken villin HP35'] = {}
systems['chicken villin HP35']['1vii.pdb'] = path('molsysmt.data.pdb', '1vii.pdb')
systems['chicken villin HP35']['1vii.mmtf'] = path('molsysmt.data.mmtf', '1vii.mmtf')
systems['chicken villin HP35']['chicken_villin_HP35.h5msm'] = path('molsysmt.data.h5msm', 'chicken_villin_HP35.h5msm')
systems['chicken villin HP35']['chicken_villin_HP35_solvated.h5msm'] = path('molsysmt.data.h5msm', 'chicken_villin_HP35_solvated.h5msm')
systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.dcd'] = path('molsysmt.data.dcd', 'traj_chicken_villin_HP35_solvated.dcd')
systems['chicken villin HP35']['traj_chicken_villin_HP35_solvated.h5'] = path('molsysmt.data.h5', 'traj_chicken_villin_HP35_solvated.h5')


# T4 Lysozyme L99A
Expand Down
49 changes: 24 additions & 25 deletions sandbox/Tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8b87277e2fb54c069e290543ded39aff",
"model_id": "68d1b5acc00648fba4dbed24dea654e3",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -56,31 +56,25 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "f1048ba3-4aa0-4ed5-a30f-cd54dabb4c64",
"id": "5976ffbc-590e-4fc1-a7b9-30e11f4f17ca",
"metadata": {},
"outputs": [],
"source": [
"molsys_A = msm.convert(systems['T4 lysozyme L99A']['t4_lysozyme_L99A.h5msm'], to_form='molsysmt.MolSys')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7c13929f-61f7-471f-b713-4cf7c32d77fa",
"metadata": {},
"outputs": [],
"source": [
"molsys_B = msm.convert(systems['T4 lysozyme L99A']['t4_lysozyme_L99A.h5msm'], to_form='molsysmt.MolSys')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0fe83988-232e-438e-8c90-7d442b263baf",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NotImplementedConversionError",
"evalue": "Error in conversion from file:mmtf to openmm.Modeller",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNotImplementedConversionError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m molsys_A \u001b[38;5;241m=\u001b[39m \u001b[43mmsm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconvert\u001b[49m\u001b[43m(\u001b[49m\u001b[43msystems\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mT4 lysozyme L99A\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m181l.mmtf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mto_form\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mopenmm.Modeller\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/_private/digestion/digest.py:122\u001b[0m, in \u001b[0;36mdigest.<locals>.digestor.<locals>.wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(all_args[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mself\u001b[39m\u001b[38;5;124m'\u001b[39m], \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mfinal_args)\n\u001b[1;32m 121\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 122\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mfinal_args\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/basic/convert.py:554\u001b[0m, in \u001b[0;36mconvert\u001b[0;34m(molecular_system, to_form, selection, structure_indices, syntax, verbose, skip_digestion, **kwargs)\u001b[0m\n\u001b[1;32m 552\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(from_form)\u001b[38;5;241m==\u001b[39m\u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 553\u001b[0m from_form\u001b[38;5;241m=\u001b[39mfrom_form[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m--> 554\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m NotImplementedConversionError(from_form, to_form)\n\u001b[1;32m 556\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(output, (\u001b[38;5;28mlist\u001b[39m, \u001b[38;5;28mtuple\u001b[39m)):\n\u001b[1;32m 557\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(output) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"\u001b[0;31mNotImplementedConversionError\u001b[0m: Error in conversion from file:mmtf to openmm.Modeller"
]
}
],
"source": [
"output = msm.compare(molsys_A, molsys_B, attributes_type='topological', coordinates=True, box=True)"
"molsys_A = msm.convert(systems['T4 lysozyme L99A']['181l.mmtf'], to_form='openmm.Modeller')"
]
},
{
Expand All @@ -89,7 +83,12 @@
"id": "825cfd0e-bce4-4af7-b33e-03f34a2f3b5d",
"metadata": {},
"outputs": [],
"source": []
"source": [
" molsys_A = msm.convert(systems['T4 lysozyme L99A']['181l.mmtf'], to_form='openmm.Modeller')\n",
" molsys_B = msm.convert(molsys_A, to_form='molsysmt.MolSys')\n",
" output = msm.compare(molsys_A, molsys_B)\n",
" assert output == True\n"
]
}
],
"metadata": {
Expand Down

0 comments on commit ca64a98

Please sign in to comment.