SD Simulations with Submission System

Imports

[1]:
import os
#for analysis
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline

from pygromos.files.gromos_system import Gromos_System
from pygromos.files.blocks import imd_blocks
from pygromos.data.simulation_parameters_templates import template_emin

Input files

[2]:
root_dir = project_dir = os.path.abspath("../example_files/SD_Simulation/")
root_in_dir = root_dir+"/SD_input"
cnf_path = root_in_dir+"/6J29_unitedatom_optimised_geometry.cnf"
top_path = root_in_dir + "/6J29.top"
sys_name = "6J29"

#External imd_changes:
grom_system = Gromos_System(in_cnf_path=cnf_path, in_top_path=top_path, in_imd_path=template_emin,
                            system_name=sys_name, work_folder=root_in_dir)

grom_system.cnf.add_empty_box()

RUN Emin

[3]:
from pygromos.simulations.hpc_queuing.submission_systems.local import LOCAL as subSystem
from pygromos.simulations.modules.preset_simulation_modules import emin
step_name  = "a_vacuum_emin"

#Some special adaptation
grom_system.imd.BOUNDCOND.NTB =0
grom_system.imd.BOUNDCOND.NDFMIN = 0
grom_system.imd.WRITETRAJ = imd_blocks.WRITETRAJ()
grom_system.imd.WRITETRAJ.NTWX = 100
grom_system.imd.WRITETRAJ.NTWE = 100
grom_system.prepare_for_simulation()
[4]:

grom_system.save(root_dir+"/test.obj", safe=False)
[4]:
'/home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/test.obj'
[5]:
grom_system = Gromos_System.load(root_dir+"/test.obj")
[6]:
grom_system.solute_info._asdict()
[6]:
{'names': ['6J29'], 'number': 1, 'positions': [1], 'number_of_atoms': 27}
[7]:
grom_system.cnf.view
[8]:
from pygromos.simulations.modules.preset_simulation_modules import emin


emin_gromos_system = emin(in_gromos_system=grom_system,
                                 step_name=step_name,
                                 submission_system=subSystem(),
                                 in_imd_path=None)
jobID = emin_gromos_system._last_jobID
emin_gromos_system

################################################################################

a_vacuum_emin
################################################################################

============================================================
FOUND RESULT: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/analysis/data/a_vacuum_emin.cnf
 GOING TO SKIPT THIS SUBMISSION!
[8]:

GROMOS SYSTEM: a_vacuum_emin
################################################################################
WORKDIR: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input
LAST CHECKPOINT: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/test.obj

GromosXX_bin: None
GromosPP_bin: None
FILES:
        imd: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/input/a_vacuum_emin.imd
        top: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/input/a_vacuum_emin.top
        cnf: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/analysis/data/a_vacuum_emin.cnf
FUTURE PROMISE: False
SYSTEM:
        Solute: ['6J29']  resID: [1]  natoms: 27
        SOLVENT:        []  nmolecules: 0  natoms: 0


[9]:
emin_gromos_system.cnf.view
[10]:
emin_gromos_system
[10]:

GROMOS SYSTEM: a_vacuum_emin
################################################################################
WORKDIR: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input
LAST CHECKPOINT: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/test.obj

GromosXX_bin: None
GromosPP_bin: None
FILES:
        imd: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/input/a_vacuum_emin.imd
        top: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/input/a_vacuum_emin.top
        cnf: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/a_vacuum_emin/analysis/data/a_vacuum_emin.cnf
FUTURE PROMISE: False
SYSTEM:
        Solute: ['6J29']  resID: [1]  natoms: 27
        SOLVENT:        []  nmolecules: 0  natoms: 0


[11]:
emin_gromos_system.work_folder+"/analysis/data"
[11]:
'/home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/analysis/data'

RUN SD Simulation

[12]:
from pygromos.simulations.modules.preset_simulation_modules import sd

step_name  = "b_vacuum_sd"

sd_gromos_system  = sd(in_gromos_system=emin_gromos_system,
                              step_name=step_name,
                       submission_system=subSystem(nmpi=1),
                      equilibration_runs=1, simulation_runs=3)
jobID = sd_gromos_system._last_jobID

sd_gromos_system

sd_gromos_system.cnf.view
################################################################################

b_vacuum_sd
################################################################################

============================================================
FOUND RESULT: /home/mlehner/PyGromosTools/docs/sphinx_project/Examples/example_files/SD_Simulation/SD_input/b_vacuum_sd/analysis/data/b_vacuum_sd.cnf
 GOING TO SKIPT THIS SUBMISSION!

Further Analysis:

Transform the trc into a pdb traj to check it out with pymol :!)

[13]:
#final analysis dir:
from pygromos.utils import bash

out_ana = project_dir+"/c_ana"
if(not os.path.exists(out_ana)):
    bash.make_folder(out_ana)

Coordinate Analysis

[14]:
from pygromos.files.trajectory.trc import Trc

trc = sd_gromos_system.trc
trc.write_pdb(out_ana+"/sd_traj.pdb", cnf_file=cnf_path)#grom_system.cnf.path)
trc
---------------------------------------------------------------------------
NoSuchNodeError                           Traceback (most recent call last)
/tmp/ipykernel_3955/2930333405.py in <module>
      1 from pygromos.files.trajectory.trc import Trc
      2
----> 3 trc = sd_gromos_system.trc
      4 trc.write_pdb(out_ana+"/sd_traj.pdb", cnf_file=cnf_path)#grom_system.cnf.path)
      5 trc

~/PyGromosTools/pygromos/files/gromos_system/gromos_system.py in trc(self)
    657     def trc(self) -> Trc:
    658         if self._trc is None and "trc" in self._traj_files_path and self.cnf is not None and not self.cnf._future_file:
--> 659             self._trc = Trc(traj_path=self._traj_files_path["trc"], in_cnf=self.cnf)
    660         elif self._trc is None and "trc" in self._traj_files_path:
    661             self._trc = Trc(traj_path=self._traj_files_path["trc"])

~/PyGromosTools/pygromos/files/trajectory/trc.py in __init__(self, xyz, topology, time, unitcell_lengths, unitcell_angles, traj_path, in_cnf, timestep_duration, _future_file)
     55
     56         if traj_path is not None and (traj_path.endswith(".h5") or traj_path.endswith(".hf5")):
---> 57             trj = self.load(traj_path)
     58             self.__dict__.update(vars(trj))
     59

~/PyGromosTools/pygromos/files/trajectory/trc.py in load(cls, in_path, in_cnf_path, timestep_duration)
    496             o = cls(traj_path=in_path, in_cnf_path=in_cnf_path)
    497         else:
--> 498             so = super().load(in_path)
    499             o = cls(
    500                 xyz=so.xyz,

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/core/trajectory.py in load(filenames, **kwargs)
   1323         As requested by the various load functions -- it depends on the extension
   1324         """
-> 1325         return load(filenames, **kwargs)
   1326
   1327     def _savers(self):

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/core/trajectory.py in load(filename_or_filenames, discard_overlapping_frames, **kwargs)
    394     topkwargs.pop("stride", None)
    395     topkwargs.pop("start", None)
--> 396     kwargs["top"] = _parse_topology(kwargs.get("top", filename_or_filenames[0]), **topkwargs)
    397
    398     #get the right loader

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/core/trajectory.py in _parse_topology(top, **kwargs)
    172         topology = top.topology
    173     elif isinstance(top, (string_types, os.PathLike)) and (ext in ['.pdb', '.pdb.gz', '.h5','.lh5']):
--> 174         _traj = load_frame(top, 0, **kwargs)
    175         topology = _traj.topology
    176     elif isinstance(top, (string_types, os.PathLike)) and (ext in ['.prmtop', '.parm7', '.prm7']):

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/core/trajectory.py in load_frame(filename, index, top, atom_indices, **kwargs)
    312         _assert_files_or_dirs_exist(filename)
    313
--> 314     return loader(filename, frame=index, **kwargs)
    315
    316

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/formats/hdf5.py in load_hdf5(filename, stride, atom_indices, frame)
    117         else:
    118             n_frames = None
--> 119         return f.read_as_traj(n_frames=n_frames, stride=stride, atom_indices=atom_indices)
    120
    121

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/formats/hdf5.py in read_as_traj(self, n_frames, stride, atom_indices)
    516
    517         initial = int(self._frame_index)
--> 518         data = self.read(n_frames=n_frames, stride=stride, atom_indices=atom_indices)
    519         if len(data) == 0:
    520             return Trajectory(xyz=np.zeros((0, topology.n_atoms, 3)), topology=topology)

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/mdtraj/formats/hdf5.py in read(self, n_frames, stride, atom_indices)
    570             stride = int(stride)
    571
--> 572         total_n_frames = len(self._handle.root.coordinates)
    573         frame_slice = slice(self._frame_index, min(self._frame_index + n_frames, total_n_frames), stride)
    574         if frame_slice.stop - frame_slice.start == 0:

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/tables/group.py in __getattr__(self, name)
    796             self._g_add_children_names()
    797             return self.__dict__[name]
--> 798         return self._f_get_child(name)
    799
    800     def __setattr__(self, name, value):

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/tables/group.py in _f_get_child(self, childname)
    680         self._g_check_open()
    681
--> 682         self._g_check_has_child(childname)
    683
    684         childpath = join_path(self._v_pathname, childname)

~/anaconda3/envs/pygro2/lib/python3.9/site-packages/tables/group.py in _g_check_has_child(self, name)
    373         node_type = self._g_get_objinfo(name)
    374         if node_type == "NoSuchNode":
--> 375             raise NoSuchNodeError(
    376                 "group ``%s`` does not have a child named ``%s``"
    377                 % (self._v_pathname, name))

NoSuchNodeError: group ``/`` does not have a child named ``coordinates``
[15]:
traj = trc.view
traj
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/tmp/ipykernel_3955/279071187.py in <module>
----> 1 traj = trc.view
      2 traj

NameError: name 'trc' is not defined

Energy Analysis

[16]:
from pygromos.files.trajectory.tre import Tre

tre = sd_gromos_system.tre
tre

[16]:
Trajectory:
        Read from hdf save
        Contains only database

Type:
        Tre
Frames:         63       Columns:       13

[17]:
#Plot Potential Energies
V_tot = np.array(list(map(lambda x: x[2], tre.database.totals)))
step = len(tre.database.TIMESTEP_time)//10

plt.plot(tre.database.TIMESTEP_time, V_tot)
plt.xticks(np.round(list(tre.database.TIMESTEP_time[::step]),2))
plt.xlabel("$t~[ps]$")
plt.ylabel("$V~[kJ]$")
plt.title("V total timeseries")
plt.savefig(out_ana+"/potential_energy_timeseries.png")
../../_images/Examples_developer_examples_dev_example_gromos_simulation_24_0.png