Skip to content

Commit

Permalink
Merge pull request #237 from rinikerlab/GromosOBJWrapFixes
Browse files Browse the repository at this point in the history
pleasing pep8
  • Loading branch information
MTLehner committed Mar 16, 2022
2 parents 7e3a9f4 + e227fb5 commit 2453683
Show file tree
Hide file tree
Showing 37 changed files with 789 additions and 538 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 45 additions & 18 deletions examples/example_hvap.ipynb
Expand Up @@ -17,7 +17,7 @@
"source": [
"from pygromos.files.gromos_system.ff.forcefield_system import forcefield_system\n",
"from pygromos.files.gromos_system.gromos_system import Gromos_System\n",
"from pygromos.simulations.hvap_calculation.hvap_calculation import Hvap_calculation\n",
"from pygromos.simulations.approaches.hvap_calculation.hvap_calculation import Hvap_calculation\n",
"from pygromos.data.simulation_parameters_templates import template_sd"
]
},
Expand All @@ -27,7 +27,9 @@
"metadata": {},
"outputs": [],
"source": [
"pygro_env={'SHELL': '/bin/bash', 'LIBGL_ALWAYS_INDIRECT': '1', 'CONDA_EXE': '/home/mlehner/anaconda3/bin/conda', '_CE_M': '', 'WSL_DISTRO_NAME': 'Ubuntu-20.04', 'NAME': 'MarcSurface', 'GSETTINGS_SCHEMA_DIR': '/home/mlehner/anaconda3/envs/pygro/share/glib-2.0/schemas', 'LOGNAME': 'mlehner', 'CONDA_PREFIX': '/home/mlehner/anaconda3/envs/pygro', 'GSETTINGS_SCHEMA_DIR_CONDA_BACKUP': '', 'HOME': '/home/mlehner', 'LANG': 'C.UTF-8', 'WSL_INTEROP': '/run/WSL/451_interop', 'CONDA_PROMPT_MODIFIER': '(pygro) ', 'PERL5LIB': '/home/mlehner/anaconda3/envs/pygro/lib/perl/mm_pbsa', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'TERM': 'xterm-256color', '_CE_CONDA': '', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'USER': 'mlehner', 'CONDA_SHLVL': '2', 'AMBERHOME': '/home/mlehner/anaconda3/envs/pygro', 'DISPLAY': '172.21.240.1:0', 'SHLVL': '1', 'CONDA_PYTHON_EXE': '/home/mlehner/anaconda3/bin/python', 'CONDA_DEFAULT_ENV': 'pygro', 'WSLENV': '', 'XDG_DATA_DIRS': '/usr/local/share:/usr/share:/var/lib/snapd/desktop', 'PATH': '/home/mlehner/anaconda3/envs/pygro/bin:/home/mlehner/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2021.222.0_x64__79rhkp1fndgsc:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Wolfram Research/WolframScript:/mnt/c/Users/thier/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/thier/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/thier/AppData/Local/GitHubDesktop/bin:/snap/bin:/usr/local/gromacs/bin/GMXRC', 'HOSTTYPE': 'x86_64', 'CONDA_PREFIX_1': '/home/mlehner/anaconda3', '_': '/home/mlehner/anaconda3/envs/pygro/bin/python3'}"
"work_dir=os.getcwd()+\"/example_files/Hvap_files/\"\n",
"gromosXX_path=None \n",
"gromosPP_path=None"
]
},
{
Expand All @@ -36,9 +38,8 @@
"metadata": {},
"outputs": [],
"source": [
"work_dir=os.getcwd()+\"/example_files/Hvap_files/\"\n",
"gromosXX_path=None #\"/home/mlehner/gromosXX/gromosXX/BUILD/program/\"\n",
"gromosPP_path=None# \"/home/mlehner/gromosPlsPls/gromos++/BUILD/programs/\""
"ff = forcefield_system(name=\"54A7\")\n",
"ff.mol_name = \"H2O\""
]
},
{
Expand All @@ -47,8 +48,9 @@
"metadata": {},
"outputs": [],
"source": [
"ff = forcefield_system(name=\"54A7\")\n",
"ff.mol_name = \"H2O\""
"groSys = Gromos_System(work_folder=work_dir+\"init/\", system_name=\"Hvap_test\", in_smiles=\"O\",\n",
" auto_convert=True, Forcefield=ff, in_imd_path=template_sd,\n",
" in_gromosPP_bin_dir=gromosPP_path, in_gromosXX_bin_dir=gromosXX_path)"
]
},
{
Expand All @@ -57,7 +59,7 @@
"metadata": {},
"outputs": [],
"source": [
"groSys = Gromos_System(work_folder=work_dir+\"init/\", system_name=\"Hvap_test\", in_smiles=\"O\", auto_convert=True, Forcefield=ff, in_imd_path=template_sd, in_gromosPP_bin_dir=gromosPP_path, in_gromosXX_bin_dir=gromosXX_path)"
"hvap_sys=Hvap_calculation(input_system=groSys, work_folder=work_dir+\"hvap\", forcefield=ff, system_name=\"test\", useGromosPlsPls=True)"
]
},
{
Expand All @@ -66,7 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"hvap_sys=Hvap_calculation(input_system=groSys, work_folder=work_dir+\"hvap\", forcefield=ff, system_name=\"test\")"
"hvap_sys.create_liq()"
]
},
{
Expand All @@ -75,7 +77,7 @@
"metadata": {},
"outputs": [],
"source": [
"hvap_sys.submissonSystem._enviroment = pygro_env"
"hvap_sys.run_gas()"
]
},
{
Expand All @@ -84,7 +86,7 @@
"metadata": {},
"outputs": [],
"source": [
"hvap_sys.create_liq()"
"hvap_sys.run_liq()"
]
},
{
Expand All @@ -93,16 +95,14 @@
"metadata": {},
"outputs": [],
"source": [
"hvap_sys.run_gas()"
"hvap_sys.calc_hvap()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"hvap_sys.run_liq()"
"## How to deactivate binary checks:"
]
},
{
Expand All @@ -111,7 +111,17 @@
"metadata": {},
"outputs": [],
"source": [
"hvap_sys.calc_hvap()"
"#GromosLayer\n",
"from pygromos.gromos.gromosXX import GromosXX\n",
"\n",
"grom = GromosXX(_dont_check_binary=True)\n",
"\n",
"\n",
"#System Layer\n",
"from pygromos.files.gromos_system.gromos_system import Gromos_System\n",
"\n",
"Gromos_System._gromos_noBinary_checks = True\n",
"sys = Gromos_System()"
]
},
{
Expand All @@ -123,8 +133,25 @@
}
],
"metadata": {
"interpreter": {
"hash": "b1b7b2ea43b8e767316eee98e01335d045804d2d47db68b6a5827e187ee91a7e"
},
"kernelspec": {
"display_name": "Python 3.9.7 ('pygro2')",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
}
},
"nbformat": 4,
Expand Down
35 changes: 23 additions & 12 deletions examples/tutorial_gromos_pipeline.ipynb
Expand Up @@ -921,6 +921,7 @@
"# Check simulation params\n",
"in_eminBox_system.imd = template_emin #Here we use template simulation parameters, The blocks are the same as above in the vacuum case with slight deviations.\n",
"in_eminBox_system.imd.INITIALISE.NTISHI = 1\n",
"\n",
"in_eminBox_system.prepare_for_simulation()\n",
"\n",
"in_eminBox_system"
Expand Down Expand Up @@ -1565,8 +1566,8 @@
"source": [
"from matplotlib import pyplot as plt\n",
"\n",
"plt.plot(temperatures.TIMESTEP_time, temperatures.bath1, label=\"TBath1\")\n",
"plt.plot(temperatures.TIMESTEP_time, temperatures.bath2, label=\"TBath2\")\n",
"plt.plot(temperatures.index, temperatures.bath1, label=\"TBath1\")\n",
"plt.plot(temperatures.index, temperatures.bath2, label=\"TBath2\")\n",
"\n",
"plt.legend()\n",
"plt.ylabel(\"$T~[K]$\")\n",
Expand Down Expand Up @@ -1774,7 +1775,7 @@
"source": [
"#Next we plot some data of the energies to se their development.\n",
"\n",
"time_axis = energy_traj.database.TIMESTEP_time\n",
"time_axis = energy_traj.time\n",
"total_energies.totene.plot(x=time_axis, xlabel=\"t [ps]\", ylabel=\"V [kJ/mol]\", title=\"Simulation Data\", legend=True)\n",
"total_energies.totpot.plot(legend=True)\n",
"total_energies.totkin.plot(legend=True)\n"
Expand Down Expand Up @@ -1815,7 +1816,7 @@
"outputs": [],
"source": [
"#First lets get the Force Group Energy contributions:\n",
"forceGroupNonbondedContributions = energy_traj.get_nonbondedForceGroupContributions()\n",
"forceGroupNonbondedContributions = energy_traj.get_nonbondedContributions()\n",
"\n",
"#Here we give each Force Group contribution category nice names:\n",
"peptide_peptide_nonbonded = forceGroupNonbondedContributions[1][1]\n",
Expand Down Expand Up @@ -1894,13 +1895,6 @@
"coordinate_traj = out_md_system.trc\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### RMSD"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1982,8 +1976,25 @@
}
],
"metadata": {
"interpreter": {
"hash": "e7d5b70120806d05daeaf98b799438b40f063b8cf99696cad03a40d92a237582"
},
"kernelspec": {
"display_name": "Python 3.9.10 ('pygromosDev')",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
}
},
"nbformat": 4,
Expand Down
14 changes: 7 additions & 7 deletions pygromos/files/_basics/_general_gromos_file.py
Expand Up @@ -8,7 +8,7 @@
import copy
import inspect
import warnings
from typing import List, Dict, Callable
from typing import List, Dict, Callable, Union

from pygromos.files.blocks import all_blocks

Expand All @@ -30,7 +30,7 @@ class _general_gromos_file:
_block_order: List[str] = []
_future_file: bool

def __init__(self, in_value: (str or dict or None or __class__), _future_file: bool = False):
def __init__(self, in_value: Union[str, dict, None], _future_file: bool = False):
self._future_file = _future_file
if isinstance(in_value, str):
self.path = self._orig_file_path = in_value
Expand All @@ -43,10 +43,12 @@ def __init__(self, in_value: (str or dict or None or __class__), _future_file: b

elif isinstance(type(in_value), __class__):
raise NotImplementedError("This variant is not implemented")

elif in_value is None:
self.path = None
self._orig_file_path = None
# print("Empty class")

else:
raise ValueError("The given type of input could not be translated in " + str(__class__) + ".__init__")

Expand Down Expand Up @@ -302,11 +304,9 @@ def write(self, out_path: str) -> str:
str
out_path
"""
os.makedirs(os.path.dirname(out_path), exist_ok=True)
file = open(out_path, "w")
file.write(str(self))
file.close()
self.path = out_path
self._write_to_file(out_path=out_path, content_str=str(self))
self.path = os.path.abspath(out_path)
self._future_file = False

return out_path

Expand Down
12 changes: 8 additions & 4 deletions pygromos/files/blocks/_general_blocks.py
Expand Up @@ -88,14 +88,18 @@ def read_content_from_str(self, content: str):

def block_to_string(self) -> str:
result = self.name + self.line_seperator
if isinstance(self.content, list) and len(self.content) > 0 and all([isinstance(x, str) for x in self.content]):
result += self.field_seperator.join(self.content) + self.line_seperator
if (
isinstance(self.content, list)
and len(self.content) > 0
and all([isinstance(x, (str, Number)) for x in self.content])
):
result += self.field_seperator.join(map(str, self.content)) + self.line_seperator
elif (
isinstance(self.content, list)
and len(self.content) > 0
and all([isinstance(x, list) and all([isinstance(y, str) for y in x]) for x in self.content])
and all([isinstance(x, list) and all([isinstance(y, (str, Number)) for y in x]) for x in self.content])
):
result += self.line_seperator.join(map(lambda x: self.field_seperator.join(x), self.content))
result += self.line_seperator.join(map(lambda x: self.field_seperator.join(map(str, x)), self.content))
elif isinstance(self.content, (str, Number)):
result += self.field_seperator + str(self.content) + self.line_seperator
else:
Expand Down
72 changes: 53 additions & 19 deletions pygromos/files/blocks/topology_blocks.py
Expand Up @@ -3027,34 +3027,68 @@ def block_to_string(self) -> str:
return result


class SOLUTEMOLECULES(_topology_block):
class _generic_topology_groups(_topology_block):
NSM: int
NSP: List[int]

def __init__(
self,
content: (str or dict or None or __class__),
content: Union[str, dict] = None,
FORCEFIELD: FORCEFIELD = None,
MAKETOPVERSION: MAKETOPVERSION = None,
NSM: int = None,
NSP: List[int] = None,
):
super().__init__(FORCEFIELD=FORCEFIELD, MAKETOPVERSION=MAKETOPVERSION, content=content)
if NSP is not None:
if NSM is not None:
if len(NSP) == NSM:
self.NSM = NSM
else:
raise ValueError("FUn")
else:
self.NSM = len(NSP)
self.NSP = list(map(int, NSP))
super().__init__(
FORCEFIELD=FORCEFIELD, MAKETOPVERSION=MAKETOPVERSION, content=[str(NSM)] + list(map(str, NSP))
)
else:
super().__init__(FORCEFIELD=FORCEFIELD, MAKETOPVERSION=MAKETOPVERSION, content=content)

if len(self.content) == 1 and len(self.content[0]) - 1 == int(self.content[0][0]):
self.NSM = int(self.content[0][0])
self.NSP = [int(x) for x in self.content[0][1:]]
elif len(self.content) > 1:
self.NSM = int(self.content[0][0])
self.NSP = []
[
self.NSP.extend(list(map(int, t))) if (isinstance(t, list)) else self.NSP.extend([int(t)])
for t in self.content[1:]
]
else:
raise ValueError("SOLUTEMOLECULES has not the correct number of fields.")

# Clean COntent
self.content = [[self.NSM]]
self.content.extend([[x] for x in self.NSP])

class TEMPERATUREGROUPS(_topology_block):
def __init__(
self,
content: (str or dict or None or __class__),
FORCEFIELD: FORCEFIELD = None,
MAKETOPVERSION: MAKETOPVERSION = None,
):
super().__init__(FORCEFIELD=FORCEFIELD, MAKETOPVERSION=MAKETOPVERSION, content=content)
def block_to_string(self) -> str:
# Clean COntent
self.content = [[self.NSM]]
self.content.extend([[x] for x in self.NSP])

return super().block_to_string()

class PRESSUREGROUPS(_topology_block):
def __init__(
self,
content: (str or dict or None or __class__),
FORCEFIELD: FORCEFIELD = None,
MAKETOPVERSION: MAKETOPVERSION = None,
):
super().__init__(FORCEFIELD=FORCEFIELD, MAKETOPVERSION=MAKETOPVERSION, content=content)

class SOLUTEMOLECULES(_generic_topology_groups):
pass


class TEMPERATUREGROUPS(_generic_topology_groups):
pass


class PRESSUREGROUPS(_generic_topology_groups):
pass


class LJEXCEPTIONS(_topology_table_block):
Expand Down

0 comments on commit 2453683

Please sign in to comment.