Skip to content

Repex submission new #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 31 additions & 104 deletions pygromos/files/blocks/imd_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pygromos.files.blocks._general_blocks import TITLE
from pygromos.files.blocks._general_blocks import _generic_gromos_block
from pygromos.utils.utils import str2bool

# forward declarations
TITLE: TITLE = TITLE
Expand Down Expand Up @@ -288,36 +289,43 @@ class REPLICA(_generic_imd_block):
_order = [[["RETL"], ["NRET"], ["RET(1 ... NRET)"], ["LRESCALE"],
["NRELAM"], ["RELAM(1 ... NRELAM)"], ["RETS(1 ... NRELAM)"], ["NRETRIAL", "NREQUIL", "CONT"]]]

def __init__(self, RETL: bool=False, NRET: int=0, RET: List[float]=[], LRESCALE: int=0, NRELAM: int=0, RELAM: List[float]=[], RETS: List[float]=[],
def __init__(self, RETL: bool=False, NRET: int=0, RET: List[float]=[], LRESCALE: bool= False, NRELAM: int=0, RELAM: List[float]=[], RETS: List[float]=[],
NRETRIAL: int=0, NREQUIL: int=0,
CONT: bool=False, content=None):
super().__init__(used=True, content=content)
if content is None:
self.RETL = bool(RETL)
if isinstance(RETL, str):
self.RETL = str2bool(RETL)
else: self.RETL = bool(RETL)

self.NRET = int(NRET)
self.RET = RET

self.LRESCALE = bool(LRESCALE)


if isinstance(LRESCALE, str):
self.LRESCALE = str2bool(LRESCALE)
else :self.LRESCALE = bool(LRESCALE)

self.NRELAM = int(NRELAM)
self.RELAM = RELAM
self.RETS = RETS

self.NRETRIAL = int(NRETRIAL)
self.NREQUIL = int(NREQUIL)
self.CONT = bool(CONT)

if isinstance(CONT, str):
self.CONT = str2bool(CONT)
else: self.CONT = bool(CONT)

def read_content_from_str(self, content: List[str]):
try:
setattr(self, "RETL", int(content[1].split()[0]))
setattr(self, "RETL", str2bool(content[1].split()[0]))
setattr(self, "NRET", int(content[3].split()[0]))
T_values = list(map(float, content[5].split()))
if(len(T_values)== self.NRET):
setattr(self, "RET", T_values)
else:
raise IOError("REPLICA: NRET was not equal to the number of Temperatures (RET) in IMD!")
setattr(self, "LRESCALE", int(content[7].split()[0]))
setattr(self, "LRESCALE", str2bool(content[7].split()[0]))
setattr(self, "NRELAM", int(content[9].split()[0]))
lambda_val = list(map(float, content[11].split()))
if(len(lambda_val)== self.NRELAM):
Expand All @@ -333,7 +341,7 @@ def read_content_from_str(self, content: List[str]):
except Exception as err:
raise IOError("Could not parse block from str - "+__class__.__name__+"\n"+str(err.args))

class NEW_REPLICA_EDS(_generic_imd_block):
class REPLICA_EDS(_generic_imd_block):
"""REPLICA_EDS Block

This block is controlling the REPLICA_EDS settings in gromos and is basically a mixture of EDS and RE block. (Don't use them when using this block!)
Expand Down Expand Up @@ -375,8 +383,8 @@ class NEW_REPLICA_EDS(_generic_imd_block):

NRETRIAL: int
NREQUIL: int
EDS_STAT_OUT: int
CONT: bool
EDS_STAT_OUT: int
PERIODIC: int

_order = [[["REEDS"], ["NRES", "NUMSTATES", "NEOFF"], ["RES(1 ... NRES)"],
Expand All @@ -387,8 +395,11 @@ def __init__(self, REEDS: bool=False, NRES: int=0, NUMSTATES: int=0, NEOFF: int=
EDS_STAT_OUT: int=0, CONT: bool=False, PERIODIC: int=0, content=None):
super().__init__(used=True, content=content)
if content is None:
self.REEDS = bool(REEDS)


if isinstance(REEDS, str):
self.REEDS = str2bool(REEDS)
else: self.REEDS = bool(REEDS)

self.NRES = int(NRES)
self.NEOFF = int(NEOFF)
self.NUMSTATES = int(NUMSTATES)
Expand All @@ -398,102 +409,20 @@ def __init__(self, REEDS: bool=False, NRES: int=0, NUMSTATES: int=0, NEOFF: int=

self.NRETRIAL = int(NRETRIAL)
self.NREQUIL = int(NREQUIL)
self.CONT = bool(CONT)

if isinstance(CONT, str):
self.CONT = str2bool(CONT)
else: self.CONT = bool(CONT)

self.EDS_STAT_OUT = int(EDS_STAT_OUT)
self.PERIODIC = int(PERIODIC)

def read_content_from_str(self, content: List[str]):
try:
setattr(self, "REEDS", int(content[1].split()[0]))
setattr(self, "NRES", int(content[3].split()[0]))
setattr(self, "NEOFF", int(content[3].split()[1]))
setattr(self, "NUMSTATES", int(content[3].split()[2]))
s_values = list(map(float, content[5].split()))
if(len(s_values)== self.NRES):
setattr(self, "RES", s_values)
else:
raise IOError("REPLICA_EDS: NRES was not equal to the number of s-values in IMD!")
EIR = []
for ind in range(7, 7+self.NUMSTATES):
EIR_line = list(map(float, content[ind].split()))
if(len(EIR_line) != self.NRES):
raise IOError("REPLICA_EDS: NRES was not equal to the number of EIRs given in IMD!")
EIR.append(EIR_line)
setattr(self, "EIR", EIR)
[setattr(self, key, int(value)) for key, value in zip(self._order[0][-1], content[-1].split()) ]

except Exception as err:
raise IOError("Could not parse block from str - "+__class__.__name__+"\n"+str(err.args))


class REPLICA_EDS(_generic_imd_block):
name: str = "REPLICA_EDS"

REEDS: bool

NRES: int
NUMSTATES: int

RES: List[float]
EIR: List[float]

NRETRIAL: int
NREQUIL: int
EDS_STAT_OUT: int
CONT: bool

_order = [[["REEDS"], ["NRES", "NUMSTATES"], ["RES(1 ... NRES)"],
["EIR(NUMSTATES x NRES)"], ["NRETRIAL", "NREQUIL", "CONT", "EDS_STAT_OUT"]]]

def __init__(self, REEDS: bool=True, NRES: int=0, NUMSTATES: int=0, RES: List[float]=[0], EIR: List[List[float]]=[[0]], NRETRIAL: int=0,
NREQUIL: int=0,
EDS_STAT_OUT: int=0, CONT: bool=True, content=None):
"""REPLICA_EDS Block

This block is controlling the REPLICA_EDS settings in gromos and is basically a mixture of EDS and RE block. (Don't use them when using this block!)

Attributes
----------
REEDS: bool
Shall REEDS be activated?
NRES: int
Number of s-Values
NUMSTATES: int
Number of EDS-states

RES: List[float]
s_values for all replicas
EIR: List[List[float]]
energy offsets for all replicas and all states List[List[float]] = REPLICA[EDS_STATE[EIR]]
NERTRIAL: int
How many replica exchanges trials should be executed? (NRETRIAL*STEP.NSTLIM == total simulation time)
NREQUIL: int
How many equilibration runs shall be exectured? (NREQUIL*STEP.NSTLIM == total simulation time)
EDS_STAT_OUT: int
Shall the replica exchange information be outputted? (__future__ frequency of output.)
CONT: bool
Is this a continuation run?
"""
super().__init__(used=True, content=content)
if content is None:
self.REEDS = REEDS

self.NRES = NRES
self.NUMSTATES = NUMSTATES

self.RES = RES
self.EIR = EIR

self.NRETRIAL = NRETRIAL
self.NREQUIL = NREQUIL
self.CONT = CONT
self.EDS_STAT_OUT = EDS_STAT_OUT

def read_content_from_str(self, content: List[str]):
try:
setattr(self, "REEDS", int(content[1].split()[0]))
setattr(self, "REEDS", str2bool(content[1].split()[0]))
setattr(self, "NRES", int(content[3].split()[0]))
setattr(self, "NUMSTATES", int(content[3].split()[1]))
setattr(self, "NEOFF", int(content[3].split()[2]))
s_values = list(map(float, content[5].split()))
if(len(s_values)== self.NRES):
setattr(self, "RES", s_values)
Expand All @@ -511,8 +440,6 @@ def read_content_from_str(self, content: List[str]):
except Exception as err:
raise IOError("Could not parse block from str - "+__class__.__name__+"\n"+str(err.args))



class BOUNDCOND(_generic_imd_block):
"""Boundary Condition Block

Expand Down Expand Up @@ -2029,4 +1956,4 @@ def __init__(self, NTRNG: int=0, NTGSL: int=0, content=None):
super().__init__(used=True, content=content)
if content is None:
self.NTRNG = int(NTRNG)
self.NTGSL = int(NTGSL)
self.NTGSL = int(NTGSL)
6 changes: 0 additions & 6 deletions pygromos/files/simulation_parameters/imd.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class Imd(_general_gromos_file._general_gromos_file):
INITIALISE: blocks.INITIALISE

REPLICA_EDS: blocks.REPLICA_EDS
NEW_REPLICA_EDS: blocks.NEW_REPLICA_EDS

REPLICA: blocks.REPLICA

QMMM: blocks.QMMM
Expand Down Expand Up @@ -134,9 +132,6 @@ def edit_REEDS(self, REEDS:(bool or int)=None, NUMSTATES:int=None, SVALS: (Numbe

# specific relations are rescued here
reeds_block = self.REPLICA_EDS
print(type(reeds_block))


if(isinstance(REEDS, bool)):
reeds_block.REEDS = REEDS

Expand Down Expand Up @@ -179,7 +174,6 @@ def edit_REEDS(self, REEDS:(bool or int)=None, NUMSTATES:int=None, SVALS: (Numbe

if(isinstance(EIR, (Number , Iterable))):
EIR_matrix = []
print(EIR)
# single number
if isinstance(EIR, Number): # depends on SVALS and NRES
EIR_vector = [str(EIR) for x in range(reeds_block.NUMSTATES)]
Expand Down
44 changes: 36 additions & 8 deletions pygromos/gromos/gromosXX.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from pygromos.utils.utils import time_wait_s_for_filesystem
from pygromos.gromos.utils import gromosTypeConverter

from pygromos.files.simulation_parameters.imd import Imd
import glob

class _Gromos:
"""
GromosXX
Expand Down Expand Up @@ -220,7 +223,7 @@ def md_run(self, in_topo_path: str, in_coord_path: str, in_imd_path: str, out_pr
def repex_run(self, in_topo_path: str, in_coord_path: str, in_imd_path: str, out_prefix: str,
in_pert_topo_path: str = None, in_disres_path: str = None, in_posresspec_path: bool = False, in_refpos_path: bool = False,
out_trc: bool = True, out_tre: bool = True, out_trs: bool = False, out_trg:bool = False,
nomp: int = 1, nmpi: int = 1, verbose: bool = True) -> str:
out_trf: bool = False, out_trv: bool = False, nomp: int = 1, nmpi: int = 1, verbose: bool = True) -> str:
"""
This function is a wrapper for gromosXX repex_mpi. You can directly execute the gromosXX repex_mpi in a bash enviroment here.

Expand Down Expand Up @@ -271,7 +274,13 @@ def repex_run(self, in_topo_path: str, in_coord_path: str, in_imd_path: str, out

out_trg : bool, optional
do you want to output the free energy trajectory (x.trg) file? (needs also an output number in write block of imd!)


out_trf : bool, optional
do you want to output the free energy trajectory (x.trg) file? (needs also an output number in write block of imd!)

out_trv : bool, optional
do you want to output the free energy trajectory (x.trg) file? (needs also an output number in write block of imd!)

queueing_systems : NONE
This var is not in use yet! - under development

Expand Down Expand Up @@ -303,17 +312,32 @@ def repex_run(self, in_topo_path: str, in_coord_path: str, in_imd_path: str, out
command += ["@topo", str(in_topo_path)]
else:
raise IOError("Did not get an input top file. Got: " + in_topo_path)

if in_imd_path:
command += ["@input", str(in_imd_path)]
else:
raise IOError("Did not get an input imd file. Got: " + in_imd_path)

# Input cnf file depends if we have the CONT keyword or not
# with CONT == 1, the convention is to give the name of the
# file without the "_1" extension

imd = Imd(in_imd_path)
if hasattr(imd, "REPLICA") and imd.REPLICA is not None and imd.REPLICA.CONT:
tmp_path = "/".join(os.path.abspath(in_coord_path).split('/')[:-1])
in_coord_path = sorted(glob.glob(tmp_path +'/*.cnf'))[0]
in_coord_path = in_coord_path.replace("_1.cnf", ".cnf")

elif hasattr(imd, "REPLICA_EDS") and imd.REPLICA_EDS is not None and imd.REPLICA_EDS.CONT:
tmp_path = "/".join(os.path.abspath(in_coord_path).split('/')[:-1])
in_coord_path = sorted(glob.glob(tmp_path +'/*.cnf'))[0]
in_coord_path = in_coord_path.replace("_1.cnf", ".cnf")

if in_coord_path:
command += ["@conf", str(in_coord_path)]
else:
raise IOError("Did not get an input coord file. Got: " + in_coord_path)

if in_imd_path:
command += ["@input", str(in_imd_path)]
else:
raise IOError("Did not get an input imd file. Got: " + in_imd_path)

if in_pert_topo_path:
command += ["@pttopo", str(in_pert_topo_path)]

Expand All @@ -337,7 +361,11 @@ def repex_run(self, in_topo_path: str, in_coord_path: str, in_imd_path: str, out
command += ["@tre", str(out_prefix + ".tre")]
if out_trg:
command += ["@trg", str(out_prefix + ".trg")]

if out_trf:
command += ["@trf", str(out_prefix + ".trf")]
if out_trv:
command += ["@trv", str(out_prefix + ".trv")]

command += ["@repout", str(out_prefix + "_repout.dat")]
command += ["@repdat", str(out_prefix + "_repdat.dat")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def do(in_simSystem: Gromos_System,
simulation_run_num: int,
equilibration_run_num: int = 0,
work_dir: str = None,
initialize_first_run= False, reinitialize_every_run= False,
initialize_first_run= True, reinitialize_every_run= False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm against this change. I believe PyGromos should by default not change anything.

analysis_script_path: str = None,
submission_system:_SubmissionSystem = LSF(),
previous_job_ID: int = None, no_double_submit:bool=False,
Expand Down
Loading