diff --git a/molsysmt/_private/digestion/argument/file.py b/molsysmt/_private/digestion/argument/file.py new file mode 100644 index 000000000..b5e3b8ff4 --- /dev/null +++ b/molsysmt/_private/digestion/argument/file.py @@ -0,0 +1,26 @@ +from ...exceptions import ArgumentError + +def digest_file(file, caller=None): + + if caller.endswith('write_topology_in_msmh5'): + + from h5py._hl.files import File as h5py_File + from molsysmt.native import MSMH5FileHandler + + if isinstance(file, h5py_File): + if 'type' in file.attrs: + return file + + elif isinstance(file, MSMH5FileHandler): + return file + + else: + + from molsysmt.form.file_msmh5.is_form import is_form as is_file_msmh5_form + file_is_msmh5 = is_file_msmh5_form(file) + if file_is_msmh5: + return file + + + raise ArgumentError('file', value=file, caller=caller, message=None) + diff --git a/molsysmt/form/openmm_Simulation/__init__.py b/molsysmt/form/openmm_Simulation/__init__.py index 6b1014ace..5d5229ab1 100644 --- a/molsysmt/form/openmm_Simulation/__init__.py +++ b/molsysmt/form/openmm_Simulation/__init__.py @@ -17,6 +17,7 @@ from .iterators import StructuresIterator, TopologyIterator from .to_file_pdb import to_file_pdb +from .to_file_msmpk import to_file_msmpk from .to_molsysmt_Topology import to_molsysmt_Topology from .to_openmm_Context import to_openmm_Context from .to_openmm_Topology import to_openmm_Topology @@ -28,6 +29,7 @@ _convert_to={ 'openmm.Simulation': extract, 'file:pdb': to_file_pdb, + 'file:msmpk': to_file_msmpk, 'molsysmt.Topology': to_molsysmt_Topology, 'openmm.Context': to_openmm_Context, 'openmm.Topology': to_openmm_Topology, diff --git a/molsysmt/form/openmm_Simulation/is_form.py b/molsysmt/form/openmm_Simulation/is_form.py index 95284fcfa..464a8b193 100644 --- a/molsysmt/form/openmm_Simulation/is_form.py +++ b/molsysmt/form/openmm_Simulation/is_form.py @@ -1,6 +1,6 @@ def is_form(item): - item_fullname = item.__class__.__module__+'.'+item.__class__.__name__ + from openmm.app.simulation import Simulation - return 'openmm.Simulation'==item_fullname + return isinstance(item, Simulation) diff --git a/molsysmt/form/openmm_Simulation/to_file_msmpk.py b/molsysmt/form/openmm_Simulation/to_file_msmpk.py new file mode 100644 index 000000000..6857c1a73 --- /dev/null +++ b/molsysmt/form/openmm_Simulation/to_file_msmpk.py @@ -0,0 +1,15 @@ +from molsysmt._private.digestion import digest + +@digest(form='openmm.Simulation') +def to_file_msmpk(item, atom_indices='all', structure_indices='all', output_filename=None): + + from . import to_molsysmt_MolSys as openmm_Simulation_to_molsysmt_MolSys + from ..molsysmt_MolSys import to_file_msmpk as molsysmt_MolSys_to_file_msmpk + + tmp_item = openmm_Simulation_to_molsysmt_MolSys(item, atom_indices=atom_indices, + structure_indices=structure_indices) + + tmp_item = molsysmt_MolSys_to_file_msmpk(tmp_item, output_filename=output_filename) + + return tmp_item + diff --git a/molsysmt/form/openmm_Simulation/to_molsysmt_MolSys.py b/molsysmt/form/openmm_Simulation/to_molsysmt_MolSys.py index 500508a0a..1fd4b5140 100644 --- a/molsysmt/form/openmm_Simulation/to_molsysmt_MolSys.py +++ b/molsysmt/form/openmm_Simulation/to_molsysmt_MolSys.py @@ -9,7 +9,7 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all'): tmp_item = MolSys() tmp_item.topology = openmm_Simulation_to_molsysmt_Topology(item, atom_indices=atom_indices) - tmp_item.trajectory = openmm_Simulation_to_molsysmt_Structures(item, atom_indices=atom_indices, structure_indices=structure_indices) + tmp_item.structures = openmm_Simulation_to_molsysmt_Structures(item, atom_indices=atom_indices, structure_indices=structure_indices) return tmp_item diff --git a/molsysmt/form/openmm_Simulation/to_openmm_Topology.py b/molsysmt/form/openmm_Simulation/to_openmm_Topology.py index d15356f46..d081a7c1a 100644 --- a/molsysmt/form/openmm_Simulation/to_openmm_Topology.py +++ b/molsysmt/form/openmm_Simulation/to_openmm_Topology.py @@ -3,7 +3,7 @@ @digest(form='openmm.Simulation') def to_openmm_Topology(item, atom_indices='all'): - from molsysmt.form.openmm_Topology import extract_openmm_Topology + from molsysmt.form.openmm_Topology import extract as extract_openmm_Topology tmp_item = item.topology tmp_item = extract_openmm_Topology(tmp_item, atom_indices=atom_indices) diff --git a/molsysmt/form/openmm_Topology/__init__.py b/molsysmt/form/openmm_Topology/__init__.py index 8a480cdc4..9d9694277 100644 --- a/molsysmt/form/openmm_Topology/__init__.py +++ b/molsysmt/form/openmm_Topology/__init__.py @@ -16,10 +16,11 @@ from .set import * from .iterators import TopologyIterator +from .write_topology_in_msmh5 import write_topology_in_msmh5 + from .to_string_pdb_text import to_string_pdb_text from .to_file_pdb import to_file_pdb from .to_file_psf import to_file_psf -from .to_file_msmh5 import to_file_msmh5 from .to_molsysmt_MolSys import to_molsysmt_MolSys from .to_molsysmt_Topology import to_molsysmt_Topology from .to_mdtraj_Topology import to_mdtraj_Topology @@ -39,7 +40,6 @@ 'string:pdb_text': to_string_pdb_text, 'file:pdb': to_file_pdb, 'file:psf': to_file_psf, - 'file:msmh5': to_file_msmh5, 'molsysmt.MolSys': to_molsysmt_MolSys, 'molsysmt.Topology': to_molsysmt_Topology, 'mdtraj.Topology': to_mdtraj_Topology, diff --git a/molsysmt/form/openmm_Topology/to_file_msmh5.py b/molsysmt/form/openmm_Topology/to_file_msmh5.py deleted file mode 100644 index ab027097c..000000000 --- a/molsysmt/form/openmm_Topology/to_file_msmh5.py +++ /dev/null @@ -1,26 +0,0 @@ -from molsysmt._private.digestion import digest -import h5py - -@digest(form='openmm.Topology') -def to_file_msmh5(item, atom_indices='all', coordinates=None, output_filename=None): - - from molsysmt.native.file_msmh5 import version as msmh5_version - - fff = h5py.File(output_filename, "w") - - fff.attrs['version'] = "1.0" - fff.attrs['type'] = "msmh5" - fff.attrs['creator'] = "molsysmt" - - add_topology_to_msmh5(item, fff, atom_indices=atom_indices, coordinates=coordinates) - - fff.close() - - tmp_item = output_filename - - return tmp_item - -@digest(form='openmm.Topology') -def add_topology_to_msmh5(item, file, atom_indices='all', coordinates=None): - - raise NotImplementedError diff --git a/molsysmt/form/openmm_Topology/write_topology_in_msmh5.py b/molsysmt/form/openmm_Topology/write_topology_in_msmh5.py new file mode 100644 index 000000000..e72befcdd --- /dev/null +++ b/molsysmt/form/openmm_Topology/write_topology_in_msmh5.py @@ -0,0 +1,13 @@ +from molsysmt._private.digestion import digest + +@digest(form='openmm.Topology') +def write_topology_in_msmh5(item, file, atom_indices='all'): + + from . import to_molsysmt_Topology as openmm_Topology_to_molsysmt_Topology + from ..molsysmt_Topology import write_topology_in_msmh5 as write_molsysmt_Topology_in_msmh5 + + molsysmt_Topology = openmm_Topology_to_molsysmt_Topology(item, atom_indices=atom_indices) + write_molsysmt_Topology_in_msmh5(molsysmt_Topology, file) + + pass + diff --git a/molsysmt/native/msmh5_file_handler.py b/molsysmt/native/msmh5_file_handler.py index 7eb5cde29..ee0934b4e 100644 --- a/molsysmt/native/msmh5_file_handler.py +++ b/molsysmt/native/msmh5_file_handler.py @@ -31,10 +31,11 @@ def __init__(self, filename, io_mode='r', creator='MolSysMT', compression="gzip" if closed: self.file.close() - def write_topology(topology, selection='all', syntax='MolSysMT'): + def write_topology(self, topology, selection='all', syntax='MolSysMT'): from molsysmt.basic import get_form, select, convert from molsysmt._private.variables import is_all + from molsysmt.form import _dict_modules if is_all(selection): atom_indices = 'all' @@ -43,11 +44,11 @@ def write_topology(topology, selection='all', syntax='MolSysMT'): try: topology_form = get_form(topology) - _dict_modules[topology_form].write_topology_in_msmh5(topology, self.file, + _dict_modules[topology_form].write_topology_in_msmh5(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_msmh5(aux_topology, self.file, + _dict_modules['molsysmt.Topology'].write_topology_in_msmh5(aux_topology, file=self.file, atom_indices=atom_indices) del(aux_topology) @@ -73,38 +74,36 @@ def _new_msmfile(filename, creator='MolSysMT', compression="gzip", compression_o file.attrs['int_precision'] = int_precision file.attrs['float_precision'] = int_precision - structures_sd=file['structures'] - if length_unit is None: - structures_sd.attrs['length_unit']=puw.get_standard_units(dimensionality={'[L]':1}, form='string') + file.attrs['length_unit']=puw.get_standard_units(dimensionality={'[L]':1}, form='string') else: - structures_sd.attrs['length_unit']=puw.get_unit(length_unit, to_form='string') + file.attrs['length_unit']=puw.get_unit(length_unit, to_form='string') if time_unit is None: - structures_sd.attrs['time_unit']=puw.get_standard_units(dimensionality={'[T]':1}, form='string') + file.attrs['time_unit']=puw.get_standard_units(dimensionality={'[T]':1}, form='string') else: - structures_sd.attrs['time_unit']=puw.get_unit(time_unit, to_form='string') + file.attrs['time_unit']=puw.get_unit(time_unit, to_form='string') if energy_unit is None: - structures_sd.attrs['energy_unit']=puw.get_standard_units(dimensionality={'[L]':2, '[M]':1, + file.attrs['energy_unit']=puw.get_standard_units(dimensionality={'[L]':2, '[M]':1, '[T]':-2, '[mol]':-1}, form='string') else: - structures_sd.attrs['energy_unit']=puw.get_unit(energy_unit, to_form='string') + file.attrs['energy_unit']=puw.get_unit(energy_unit, to_form='string') if temperature_unit is None: - structures_sd.attrs['temperature_unit']=puw.get_standard_units(dimensionality={'[K]':1}, form='string') + file.attrs['temperature_unit']=puw.get_standard_units(dimensionality={'[K]':1}, form='string') else: - structures_sd.attrs['temperature_unit']=puw.get_unit(temperature_unit, to_form='string') + file.attrs['temperature_unit']=puw.get_unit(temperature_unit, to_form='string') if temperature_unit is None: - structures_sd.attrs['charge_unit']=puw.get_standard_units(dimensionality={'[A]':1, '[T]':1}, form='string') + file.attrs['charge_unit']=puw.get_standard_units(dimensionality={'[A]':1, '[T]':1}, form='string') else: - structures_sd.attrs['charge_unit']=puw.get_unit(temperature_unit, to_form='string') + file.attrs['charge_unit']=puw.get_unit(temperature_unit, to_form='string') if temperature_unit is None: - structures_sd.attrs['mass_unit']=puw.get_standard_units(dimensionality={'[M]':1}, form='string') + file.attrs['mass_unit']=puw.get_standard_units(dimensionality={'[M]':1}, form='string') else: - structures_sd.attrs['mass_unit']=puw.get_unit(mass_unit, to_form='string') + file.attrs['mass_unit']=puw.get_unit(mass_unit, to_form='string') global_dataset_options = { 'compression':compression, @@ -193,15 +192,16 @@ def _new_msmfile(filename, creator='MolSysMT', compression="gzip", compression_o # Structures - structures_sd = file.create_group("structures_sd") + structures_sd = file.create_group("structures") structures_sd.attrs['n_atoms'] = 0 - structures_sd.attrs['n_structures_sd'] = 0 - structures_sd.attrs['n_structures_sd_to_be_written'] = 0 + structures_sd.attrs['n_structures'] = 0 + structures_sd.attrs['n_structures_written'] = 0 structures_sd.attrs['constant_time_step']=False structures_sd.attrs['time_step']=0.0 structures_sd.attrs['constant_id_step']=False structures_sd.attrs['id_step']=0 structures_sd.attrs['constant_box']=False + structures_sd.attrs['pbc']='pbc' # none, cell, mic, continuous structures_sd.create_dataset('id', (0,), dtype=int_type, maxshape=(None,), **global_dataset_options) structures_sd.create_dataset('time', (0,), dtype=float_type, maxshape=(None,), **global_dataset_options) diff --git a/molsysmt/thirds/openmm/reporters/msmh5.py b/molsysmt/thirds/openmm/reporters/msmh5.py index 4488ce1c5..185c379cf 100644 --- a/molsysmt/thirds/openmm/reporters/msmh5.py +++ b/molsysmt/thirds/openmm/reporters/msmh5.py @@ -1,14 +1,16 @@ from molsysmt._private.variables import is_all import numpy as np +import openmm as mm +from openmm import unit class MSMH5Reporter(object): - def __init__(self, file, reportInterval, selection='all', steps=None, + def __init__(self, file, reportInterval, steps, selection='all', topology=True, time=True, box=True, coordinates=True, velocities=False, potentialEnergy=False, kineticEnergy=False, temperature=False, includeInitialContext=True, constantReportInterval=True, constantStepSize=True, constantBox=True, - compression='gzip', compression_opts=4, + compression='lzf', compression_opts=None, int_precision='single', float_precision='single', syntax='MolSysMT'): @@ -45,8 +47,7 @@ def __init__(self, file, reportInterval, selection='all', steps=None, self._selection_is_all = False self._syntax = syntax - self._n_intervals_to_be_reported = None - self._n_intervals_reported = 0 + self._n_structures_reported = 0 self._file_handler = MSMH5FileHandler(file, io_mode='w', creator='OpenMM', compression=compression, compression_opts=compression_opts, @@ -59,7 +60,6 @@ def __init__(self, file, reportInterval, selection='all', steps=None, def _initialize(self, simulation): from molsysmt.basic import select, get - import openmm as mm system = simulation.system context = simulation.context @@ -68,6 +68,7 @@ def _initialize(self, simulation): if not is_all(self._selection): self._selection = select(topology, selection=self._selection, syntax=self._syntax) + self._selection_is_all = False self._n_atoms = len(self._selection) else: self._selection_is_all = True @@ -81,7 +82,7 @@ def _initialize(self, simulation): if self._temperature: dof = 0 for i in range(system.getNumParticles()): - if system.getParticleMass(i) > 0*unit.dalton: + if system.getParticleMass(i) > 0.0*unit.dalton: dof += 3 dof -= system.getNumConstraints() if any(isinstance(frc, mm.CMMotionRemover) for frc in frclist): @@ -92,53 +93,53 @@ def _initialize(self, simulation): if system.usesPeriodicBoundaryConditions(): if self._constant_box: self._constant_box = True # Barostat needs to be checked - self._structures_sd.attr['constant_box']=True + self._structures_sd.attrs['constant_box']=True if self._constant_report_interval: - self._structures_sd.attr['constant_id_step']=True + self._structures_sd.attrs['constant_id_step']=True if self._constant_step_size: self._step_size = integrator.getStepSize() - self._structures_sd.attr['constant_time_step']=True + self._structures_sd.attrs['constant_time_step']=True if self._steps is not None: - self.n_intervals_to_be_reported = int(self._steps/self._report_interval) + self._steps = int(self._steps/self._report_interval) if self._include_initial_context: - self.n_intervals_to_be_reported +=1 + self._steps +=1 if self._constant_report_interval: - self._structures_sd['id'].resize((1)) + self._structures_sd['id'].resize((1,)) else: - self._structures_sd['id'].resize((n_intervals_to_be_reported)) + self._structures_sd['id'].resize((self._steps)) if self._time: if self._constant_report_interval and self._constant_step_size: - self._structures_sd['time'].resize((1)) + self._structures_sd['time'].resize((1,)) else: - self._structures_sd['time'].resize((n_intervals_to_be_reported)) + self._structures_sd['time'].resize((self._steps)) if self._box: if self._constant_box: self._structures_sd['box'].resize((1, 3, 3)) else: - self._structures_sd['box'].resize((n_intervals_to_be_reported, 3, 3)) + self._structures_sd['box'].resize((self._steps, 3, 3)) if self._coordinates: - self._structures_sd['coordinates'].resize((n_intervals_to_be_reported, self._n_atoms, 3)) + self._structures_sd['coordinates'].resize((self._steps, self._n_atoms, 3)) if self._velocities: - self._structures_sd['velocities'].resize((n_intervals_to_be_reported, self._n_atoms, 3)) + self._structures_sd['velocities'].resize((self._steps, self._n_atoms, 3)) if self._kinetic_energy: - self._structures_sd['kinetic_energy'].resize((n_intervals_to_be_reported)) + self._structures_sd['kinetic_energy'].resize((self._steps,)) if self._potential_energy: - self._structures_sd['potential_energy'].resize((n_intervals_to_be_reported)) + self._structures_sd['potential_energy'].resize((self._steps,)) if self._temperature: - self._structures_sd['temperature'].resize((n_intervals_to_be_reported)) + self._structures_sd['temperature'].resize((self._steps,)) - self._structures_sd.attrs['n_structures_to_be_written'] = self._n_intervals_to_be_reported + self._structures_sd.attrs['n_structures'] = self._steps if self._include_initial_context: initial_state = simulation.context.getState(getPositions=self._needs_positions, @@ -152,13 +153,17 @@ def _initialize(self, simulation): def describeNextReport(self, simulation): - steps_left = simulation.currentStep % self._reportInterval - steps = self._reportInterval - steps_left - return (steps, self._needsPositions, self._needsVelocities, self._needsForces, self._needEnergy) + if not self._initialized: + self._initialize(simulation) + + steps_left = simulation.currentStep % self._report_interval + steps = self._report_interval - steps_left + return (steps, self._needs_positions, self._needs_velocities, self._needs_forces, + self._needs_energy) def report(self, simulation, state): - index = self._n_intervals_reported + index = self._n_structures_reported if self._id: self._structures_sd['id'][index] = simulation.currentStep @@ -199,8 +204,8 @@ def report(self, simulation, state): self._structures_sd['temperature'][index] = temperature._value - self._n_intervals_reported += 1 - self._structures_sd.attrs['n_structures'] = self._n_intervals_reported + self._n_structures_reported += 1 + self._structures_sd.attrs['n_structures_written'] = self._n_structures_reported pass diff --git a/sandbox/Test-Copy1.ipynb b/sandbox/Test-Copy1.ipynb new file mode 100644 index 000000000..1640458fa --- /dev/null +++ b/sandbox/Test-Copy1.ipynb @@ -0,0 +1,285 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85d75849-5640-43b7-8b93-87cdbf6b8792", + "metadata": {}, + "source": [ + "# Test2" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "08aee8bc-0efe-44a5-9aa6-24131ae8137e", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f9f8114975664ee5820dc4159d40d228", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import molsysmt as msm" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "4ad7bc96-0f77-4bb5-bfa0-fa5296ed5d3d", + "metadata": {}, + "outputs": [], + "source": [ + "import openmm as mm\n", + "from openmm import app\n", + "from openmm import unit" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4d812609-a0d8-462f-844d-58fb5fd20044", + "metadata": {}, + "outputs": [], + "source": [ + "molsys = msm.convert('initial.msmpk')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "f8c8da61-9fcd-464e-8527-cc07294a3f59", + "metadata": {}, + "outputs": [], + "source": [ + "topology = msm.convert(molsys, 'openmm.Topology')\n", + "coordinates = msm.get(molsys, coordinates=True)\n", + "positions = msm.pyunitwizard.convert(coordinates[0], to_form='openmm.unit')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "faf46e30-3984-462d-b82a-67fa375d0dad", + "metadata": {}, + "outputs": [], + "source": [ + "forcefield = app.ForceField('amber14-all.xml', 'amber14/tip3p.xml')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a64d8439-6611-4129-9a4d-993cbf83ce67", + "metadata": {}, + "outputs": [], + "source": [ + "system = forcefield.createSystem(topology, nonbondedMethod=app.PME,\n", + " nonbondedCutoff=1.2*unit.nanometer, constraints=app.HBonds)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fc909c3f-345d-4c1f-b5f8-eb71eb22bf76", + "metadata": {}, + "outputs": [], + "source": [ + "integrator = mm.LangevinIntegrator(300*unit.kelvin, 1.0/unit.picosecond, 2.0*unit.femtoseconds)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "a722c9e4-cfca-43f8-8710-1c028aea6569", + "metadata": {}, + "outputs": [], + "source": [ + "platform = mm.Platform.getPlatformByName(\"CPU\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "4102c0c6-7d97-4964-bbe9-f24356e97b08", + "metadata": {}, + "outputs": [], + "source": [ + "simulation = app.Simulation(topology, system, integrator, platform)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec61ac73-777e-4d22-b3d7-cbc32b4a8cac", + "metadata": {}, + "outputs": [], + "source": [ + "simulation.context.setPositions(positions)\n", + "#simulation.minimizeEnergy()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20516706-23cc-476e-b330-b7bd22b88ef3", + "metadata": {}, + "outputs": [], + "source": [ + "msm.convert(simulation, 'initial.msmpk')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00d2a551-dd8e-4678-9e48-aa8a4765664e", + "metadata": {}, + "outputs": [], + "source": [ + "aa = msm.convert(simulation)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2aa4de52-b0fe-4bb4-9f21-5ccef4075d04", + "metadata": {}, + "outputs": [], + "source": [ + "msm.info(aa)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21c83228-ba57-450b-967b-b7b6195e2a1a", + "metadata": {}, + "outputs": [], + "source": [ + "#from molsysmt.thirds.openmm.reporters import MolSysMTTrajectoryDictReporter\n", + "#from molsysmt.thirds.openmm.reporters import MSMH5Reporter\n", + "#from mdtraj.reporters import HDF5Reporter\n", + "from molsysmt.thirds.openmm.reporters import TQDMReporter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7282a59c-8f33-45e9-914d-878659a93cac", + "metadata": {}, + "outputs": [], + "source": [ + "#dict_reporter = MolSysMTTrajectoryDictReporter(10)\n", + "#simulation.reporters.append(dict_reporter)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "044d948f-1d5f-4f43-b4ca-eac0a29235a9", + "metadata": {}, + "outputs": [], + "source": [ + "#msmh5_reporter = MSMH5Reporter('test.msmh5', 100, steps=100, selection='all',\n", + "# topology=True, time=True, box=True, coordinates=True, velocities=False,\n", + "# potentialEnergy=True, kineticEnergy=True, temperature=True,\n", + "# includeInitialContext=True, constantReportInterval=True,\n", + "# constantStepSize=True, constantBox=True,\n", + "# compression='gzip', compression_opts=4,\n", + "# int_precision='single', float_precision='single',\n", + "# syntax='MolSysMT')\n", + "#simulation.reporters.append(msmh5_reporter)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e6dac3f-1ba1-4cb4-ba4d-e11067da6a77", + "metadata": {}, + "outputs": [], + "source": [ + "#h5_reporter = HDF5Reporter('test2.msmh5', 10)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "330346e6-fd22-4fb6-b37e-e399d5c4b054", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "simulation.step(5000)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69ad2b4f-0c98-4e01-9e4c-73ba0a00ff85", + "metadata": {}, + "outputs": [], + "source": [ + "h5_reporter.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "698f41f6-803c-4865-a581-40fc5bbb4dd2", + "metadata": {}, + "outputs": [], + "source": [ + "traj = dict_reporter.finalize()\n", + "msmh5_reporter.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e0f2b4c-4248-4555-ba73-ad3cf315fb89", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "614409f6-4201-4c10-8983-c722e52a76ee", + "metadata": {}, + "outputs": [], + "source": [ + "CPU times: user 53.2 s, sys: 382 ms, total: 53.6 s\n", + "Wall time: 3.12 s" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/sandbox/Test.ipynb b/sandbox/Test.ipynb index 18de4ceb9..86d0e9836 100644 --- a/sandbox/Test.ipynb +++ b/sandbox/Test.ipynb @@ -17,7 +17,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "4d9fc4c0fdd449079c0fed4e538f3275", + "model_id": "bb10351d0a0548a698881062f85ee8e4", "version_major": 2, "version_minor": 0 }, @@ -50,147 +50,154 @@ "metadata": {}, "outputs": [], "source": [ - "molsys = msm.convert('4POC')" + "#molsys = msm.convert('4POC')\n", + "#molsys = msm.extract(molsys, selection='molecule_type==\"protein\"')\n", + "#molsys = msm.build.add_missing_hydrogens(molsys)\n", + "#molsys = msm.build.solvate(molsys)" ] }, { "cell_type": "code", "execution_count": 4, - "id": "046c5eec-7ab2-409c-9291-da9c19e67728", + "id": "af701dd9-f4c2-4731-93c4-29eaea41fd06", "metadata": {}, "outputs": [], "source": [ - "molsys = msm.extract(molsys, selection='molecule_type==\"protein\"')" + "molsys = msm.convert('initial.msmpk')" ] }, { "cell_type": "code", "execution_count": 5, - "id": "72ecea0d-a32d-49da-b929-2ceb66136b8e", + "id": "8ae23b96-3d4b-425a-af14-34db7e2b6edc", "metadata": {}, "outputs": [], "source": [ - "molsys = msm.build.add_missing_hydrogens(molsys)" + "topology = msm.convert(molsys, 'openmm.Topology')\n", + "coordinates = msm.get(molsys, coordinates=True)\n", + "positions = msm.pyunitwizard.convert(coordinates[0], to_form='openmm.unit')" ] }, { "cell_type": "code", "execution_count": 6, - "id": "5b5471e7-546b-40fc-8bae-e4efd798a3fc", + "id": "faf46e30-3984-462d-b82a-67fa375d0dad", "metadata": {}, "outputs": [], "source": [ - "molsys = msm.build.solvate(molsys)" + "forcefield = app.ForceField('amber14-all.xml', 'amber14/tip3p.xml')" ] }, { "cell_type": "code", "execution_count": 7, - "id": "faf46e30-3984-462d-b82a-67fa375d0dad", + "id": "a64d8439-6611-4129-9a4d-993cbf83ce67", "metadata": {}, "outputs": [], "source": [ - "forcefield = app.ForceField('amber14-all.xml', 'amber14/tip3p.xml')" + "system = forcefield.createSystem(topology, nonbondedMethod=app.PME,\n", + " nonbondedCutoff=1.2*unit.nanometer, constraints=app.HBonds)" ] }, { "cell_type": "code", "execution_count": 8, - "id": "610249ba-1992-4457-aa75-90f8ec791d9c", + "id": "fc909c3f-345d-4c1f-b5f8-eb71eb22bf76", "metadata": {}, "outputs": [], "source": [ - "topology = msm.convert(molsys, 'openmm.Topology')" + "integrator = mm.LangevinIntegrator(300*unit.kelvin, 1.0/unit.picosecond, 2.0*unit.femtoseconds)" ] }, { "cell_type": "code", "execution_count": 9, - "id": "a64d8439-6611-4129-9a4d-993cbf83ce67", + "id": "a722c9e4-cfca-43f8-8710-1c028aea6569", "metadata": {}, "outputs": [], "source": [ - "system = forcefield.createSystem(topology, nonbondedMethod=app.PME,\n", - " nonbondedCutoff=1.2*unit.nanometer, constraints=app.HBonds)" + "platform = mm.Platform.getPlatformByName(\"CPU\")" ] }, { "cell_type": "code", "execution_count": 10, - "id": "fc909c3f-345d-4c1f-b5f8-eb71eb22bf76", + "id": "4102c0c6-7d97-4964-bbe9-f24356e97b08", "metadata": {}, "outputs": [], "source": [ - "integrator = mm.LangevinIntegrator(300*unit.kelvin, 1.0/unit.picosecond, 2.0*unit.femtoseconds)" + "simulation = app.Simulation(topology, system, integrator, platform)" ] }, { "cell_type": "code", "execution_count": 11, - "id": "a722c9e4-cfca-43f8-8710-1c028aea6569", + "id": "ec61ac73-777e-4d22-b3d7-cbc32b4a8cac", "metadata": {}, "outputs": [], "source": [ - "platform = mm.Platform.getPlatformByName(\"CPU\")" + "simulation.context.setPositions(positions)" ] }, { "cell_type": "code", "execution_count": 12, - "id": "4102c0c6-7d97-4964-bbe9-f24356e97b08", + "id": "20516706-23cc-476e-b330-b7bd22b88ef3", "metadata": {}, "outputs": [], "source": [ - "simulation = app.Simulation(topology, system, integrator, platform)" + "#simulation.minimizeEnergy()\n", + "#msm.convert(simulation, 'initial.msmpk')" ] }, { "cell_type": "code", "execution_count": 13, - "id": "b3cbdb1e-1eb1-430e-be46-7b20a9e3928e", + "id": "21c83228-ba57-450b-967b-b7b6195e2a1a", "metadata": {}, "outputs": [], "source": [ - "coordinates = msm.get(molsys, coordinates=True)\n", - "positions = msm.pyunitwizard.convert(coordinates[0], to_form='openmm.unit')" + "#from molsysmt.thirds.openmm.reporters import MolSysMTTrajectoryDictReporter\n", + "from molsysmt.thirds.openmm.reporters import MSMH5Reporter\n", + "from mdtraj.reporters import HDF5Reporter\n", + "from molsysmt.thirds.openmm.reporters import TQDMReporter" ] }, { "cell_type": "code", "execution_count": 14, - "id": "ec61ac73-777e-4d22-b3d7-cbc32b4a8cac", + "id": "1561ddce-b2b2-4d7a-911d-c05a92cd0fa4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "7a2e3a3a37a546718ea50a67d4181e25", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0/5000 [00:00 1\u001b[0m msmh5_reporter \u001b[38;5;241m=\u001b[39m \u001b[43mMSMH5Reporter\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mtest.msmh5\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mselection\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mall\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msteps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mtopology\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtime\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbox\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcoordinates\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvelocities\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43mpotentialEnergy\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkineticEnergy\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43mincludeInitialContext\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconstantReportInterval\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43mconstantStepSize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconstantBox\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mgzip\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcompression_opts\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43mint_precision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msingle\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfloat_precision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msingle\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43msyntax\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mMolSysMT\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 9\u001b[0m simulation\u001b[38;5;241m.\u001b[39mreporters\u001b[38;5;241m.\u001b[39mappend(msmh5_reporter)\n", - "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/thirds/openmm/reporters/msmh5.py:51\u001b[0m, in \u001b[0;36mMSMH5Reporter.__init__\u001b[0;34m(self, file, reportInterval, selection, steps, topology, time, box, coordinates, velocities, potentialEnergy, kineticEnergy, temperature, includeInitialContext, constantReportInterval, constantStepSize, constantBox, compression, compression_opts, int_precision, float_precision, syntax)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_n_intervals_to_be_reported \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_n_intervals_reported \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_file_handler \u001b[38;5;241m=\u001b[39m \u001b[43mMSMH5FileHandler\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mio_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mw\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcreator\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mOpenMM\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 52\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcompression\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcompression_opts\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcompression_opts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 53\u001b[0m \u001b[43m \u001b[49m\u001b[43mint_precision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mint_precision\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfloat_precision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfloat_precision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 54\u001b[0m \u001b[43m \u001b[49m\u001b[43mlength_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mnm\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtime_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mps\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43menergy_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mkJ/mol\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 55\u001b[0m \u001b[43m \u001b[49m\u001b[43mtemperature_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mkelvin\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcharge_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43me\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmass_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mdalton\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_structures_sd \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_file_handler\u001b[38;5;241m.\u001b[39mfile[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstructures\u001b[39m\u001b[38;5;124m'\u001b[39m]\n", - "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/native/msmh5_file_handler.py:17\u001b[0m, in \u001b[0;36mMSMH5FileHandler.__init__\u001b[0;34m(self, filename, io_mode, creator, compression, compression_opts, int_precision, float_precision, length_unit, time_unit, energy_unit, temperature_unit, charge_unit, mass_unit, closed)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m io_mode\u001b[38;5;241m==\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m---> 17\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile \u001b[38;5;241m=\u001b[39m \u001b[43m_new_msmfile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcreator\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcreator\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcompression\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 18\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression_opts\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcompression_opts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mint_precision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mint_precision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[43mfloat_precision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfloat_precision\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlength_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlength_unit\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtime_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtime_unit\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[43m \u001b[49m\u001b[43menergy_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43menergy_unit\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtemperature_unit\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 21\u001b[0m \u001b[43m \u001b[49m\u001b[43mcharge_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcharge_unit\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmass_unit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmass_unit\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 23\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m io_mode\u001b[38;5;241m==\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfile \u001b[38;5;241m=\u001b[39m h5py\u001b[38;5;241m.\u001b[39mFile(filename, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/native/msmh5_file_handler.py:76\u001b[0m, in \u001b[0;36m_new_msmfile\u001b[0;34m(filename, creator, compression, compression_opts, int_precision, float_precision, length_unit, time_unit, energy_unit, temperature_unit, charge_unit, mass_unit)\u001b[0m\n\u001b[1;32m 73\u001b[0m file\u001b[38;5;241m.\u001b[39mattrs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mint_precision\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m int_precision\n\u001b[1;32m 74\u001b[0m file\u001b[38;5;241m.\u001b[39mattrs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfloat_precision\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m int_precision\n\u001b[0;32m---> 76\u001b[0m structures_sd\u001b[38;5;241m=\u001b[39m\u001b[43mfile\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mstructures\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[1;32m 78\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m length_unit \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 79\u001b[0m structures_sd\u001b[38;5;241m.\u001b[39mattrs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlength_unit\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m=\u001b[39mpuw\u001b[38;5;241m.\u001b[39mget_standard_units(dimensionality\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m[L]\u001b[39m\u001b[38;5;124m'\u001b[39m:\u001b[38;5;241m1\u001b[39m}, form\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstring\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", - "File \u001b[0;32mh5py/_objects.pyx:54\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32mh5py/_objects.pyx:55\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32m~/Myopt/miniconda3/envs/MolSysMT@uibcdf_3.10/lib/python3.10/site-packages/h5py/_hl/group.py:357\u001b[0m, in \u001b[0;36mGroup.__getitem__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 355\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid HDF5 object reference\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 356\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(name, (\u001b[38;5;28mbytes\u001b[39m, \u001b[38;5;28mstr\u001b[39m)):\n\u001b[0;32m--> 357\u001b[0m oid \u001b[38;5;241m=\u001b[39m \u001b[43mh5o\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_e\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlapl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_lapl\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 358\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 359\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAccessing a group is done with bytes or str, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 360\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnot \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;28mtype\u001b[39m(name)))\n", - "File \u001b[0;32mh5py/_objects.pyx:54\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32mh5py/_objects.pyx:55\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32mh5py/h5o.pyx:190\u001b[0m, in \u001b[0;36mh5py.h5o.open\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: \"Unable to synchronously open object (object 'structures' doesn't exist)\"" + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU times: user 47min 57s, sys: 18.4 s, total: 48min 15s\n", + "Wall time: 2min 57s\n" ] } ], "source": [ - "msmh5_reporter = MSMH5Reporter('test.msmh5', 10, selection='all', steps=100,\n", - " topology=True, time=True, box=True, coordinates=True, velocities=False,\n", - " potentialEnergy=True, kineticEnergy=True, temperature=True,\n", - " includeInitialContext=True, constantReportInterval=True,\n", - " constantStepSize=True, constantBox=True,\n", - " compression='gzip', compression_opts=4,\n", - " int_precision='single', float_precision='single',\n", - " syntax='MolSysMT')\n", - "simulation.reporters.append(msmh5_reporter)" + "%%time\n", + "simulation.step(5000)" ] }, { "cell_type": "code", "execution_count": null, - "id": "330346e6-fd22-4fb6-b37e-e399d5c4b054", + "id": "69ad2b4f-0c98-4e01-9e4c-73ba0a00ff85", "metadata": {}, "outputs": [], "source": [ - "simulation.step(100)" + "h5_reporter.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "164e05f5-dd74-4589-a483-da08e4db4561", + "metadata": {}, + "outputs": [], + "source": [ + "msmh5_reporter.close()" ] }, { @@ -267,10 +280,21 @@ { "cell_type": "code", "execution_count": null, - "id": "4e0f2b4c-4248-4555-ba73-ad3cf315fb89", + "id": "614409f6-4201-4c10-8983-c722e52a76ee", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "tqdm : 30 it/s\n", + "CPU times: user 47min 36s, sys: 18.1 s, total: 47min 54s\n", + "Wall time: 2min 45s\n", + "\n", + "tqdm + h5: 30 it/s\n", + "CPU times: user 46min 52s, sys: 17.9 s, total: 47min 10s\n", + "Wall time: 2min 44s\n", + "\n", + "\n", + "\n" + ] } ], "metadata": { diff --git a/sandbox/initial.msmpk b/sandbox/initial.msmpk new file mode 100644 index 000000000..e70e2c45d Binary files /dev/null and b/sandbox/initial.msmpk differ diff --git a/sandbox/last_10_frames.h5 b/sandbox/last_10_frames.h5 deleted file mode 100644 index 29c63def7..000000000 Binary files a/sandbox/last_10_frames.h5 and /dev/null differ diff --git a/sandbox/micro_traj_eq.h5 b/sandbox/micro_traj_eq.h5 deleted file mode 100644 index dfd9325ff..000000000 Binary files a/sandbox/micro_traj_eq.h5 and /dev/null differ diff --git a/sandbox/test.msmh5 b/sandbox/test.msmh5 deleted file mode 100644 index be0074833..000000000 Binary files a/sandbox/test.msmh5 and /dev/null differ diff --git a/sandbox/traj.h5 b/sandbox/traj.h5 deleted file mode 100644 index ae3c0138d..000000000 Binary files a/sandbox/traj.h5 and /dev/null differ diff --git a/sandbox/traj_ions.h5 b/sandbox/traj_ions.h5 deleted file mode 100644 index dd78cc83d..000000000 Binary files a/sandbox/traj_ions.h5 and /dev/null differ diff --git a/sandbox/traj_ions_peptide.h5 b/sandbox/traj_ions_peptide.h5 deleted file mode 100644 index a3f7993e4..000000000 Binary files a/sandbox/traj_ions_peptide.h5 and /dev/null differ