Compare commits

..

3 Commits

18 changed files with 317 additions and 379 deletions

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python3
import shutil
from pathlib import Path
from generate_annealing import generate_annealing
from replace_params import replace_params
def main(root_dir: Path):
simdir = root_dir / "01_an1"
if simdir.exists():
shutil.rmtree(simdir)
simdir.mkdir()
# Copy topology and replace parameters
shutil.copy(root_dir / "topology.top", simdir / "topology.top")
replace_params(root_dir / "params.ini", root_dir / "topology.top", simdir / "topology.top")
replace_params(root_dir / "params_an1.ini", root_dir / "mdp_parameters.mdp", simdir / "mdp_parameters.mdp")
replace_params(root_dir / "params.ini", simdir / "mdp_parameters.mdp", simdir / "mdp_parameters.mdp")
# Copy run.sh
shutil.copy(root_dir / "run.sh", simdir / "run.sh")
# Generate annealing section
annealing = generate_annealing(d=50, l=50, u=1000, s=50, e=2000)
# -d 20 -l 750 -u 2100 -s 50 -e 10000 -c
with (simdir / "mdp_parameters.mdp").open("a") as f:
f.write("\n")
f.write(annealing)
print(f"Annealing directory {simdir} created and filled.")
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} ROOT_DIRECTORY")
sys.exit(1)
main(Path(sys.argv[1]))

View File

@@ -1,40 +0,0 @@
#!/bin/bash
get_ini_value() {
local file=$1
local section=$2
local key=$3
awk -F '=' -v section="$section" -v key="$key" '
$0 ~ "\\[" section "\\]" { in_section = 1; next }
in_section && $1 ~ "^" key"[[:space:]]*$" {
gsub(/[[:space:]]+/, "", $2)
print $2
exit
}
$0 ~ /^\[/ { in_section = 0 }
' "$file"
}
simdir="01_an1"
rm -r "$simdir" 2>/dev/null
mkdir "$simdir"
cp topology.top "$simdir/"
"$(dirname $0)/replace_params.sh" params.ini topology.top --output "$simdir/topology.top"
"$(dirname $0)/replace_params.sh" params_an1.ini mdp_parameters.mdp --output "$simdir/mdp_parameters.mdp"
"$(dirname $0)/replace_params.sh" params.ini "$simdir/mdp_parameters.mdp" --output "$simdir/mdp_parameters.mdp"
cp "$(dirname $0)/run.sh" "$simdir/"
cp "00_em/out/out.gro" "$simdir/gro_start.gro"
annealing=$($(dirname $0)/generate_annealing.py -d 50 -l 50 -u 1000 -s 50 -e 2000)
#annealing=$($(dirname $0)/generate_annealing.py -d 30 -l 400 -u 950 -s 50 -e 2000)
echo "" >> "$simdir/mdp_parameters.mdp"
echo "$annealing" >> "$simdir/mdp_parameters.mdp"

View File

@@ -1,39 +0,0 @@
#!/bin/bash
get_ini_value() {
local file=$1
local section=$2
local key=$3
awk -F '=' -v section="$section" -v key="$key" '
$0 ~ "\\[" section "\\]" { in_section = 1; next }
in_section && $1 ~ "^" key"[[:space:]]*$" {
gsub(/[[:space:]]+/, "", $2)
print $2
exit
}
$0 ~ /^\[/ { in_section = 0 }
' "$file"
}
simdir="02_an_cooling"
rm -r "$simdir" 2>/dev/null
mkdir "$simdir"
cp topology.top "$simdir/"
"$(dirname $0)/replace_params.sh" params.ini topology.top --output "$simdir/topology.top"
"$(dirname $0)/replace_params.sh" params_an1.ini mdp_parameters.mdp --output "$simdir/mdp_parameters.mdp"
"$(dirname $0)/replace_params.sh" params.ini "$simdir/mdp_parameters.mdp" --output "$simdir/mdp_parameters.mdp"
cp "$(dirname $0)/run.sh" "$simdir/"
#cp "00_em/out/out.gro" "$simdir/gro_start.gro"
#annealing=$($(dirname $0)/generate_annealing.py -d 50 -l 180 -u 750 -e 2000 -c)
annealing=$($(dirname $0)/generate_annealing.py -d 20 -l 750 -u 2100 -s 50 -e 10000 -c)
echo "" >> "$simdir/mdp_parameters.mdp"
echo "$annealing" >> "$simdir/mdp_parameters.mdp"

View File

@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import argparse
import os
import subprocess
from pathlib import Path
from importlib.resources import files
import configparser
# --- Core function ---
def innitialize_simulation_dir(directory: Path):
os.chdir(directory)
params = configparser.ConfigParser()
params = params.read('params.ini')
template_path = files("polyamorphism_optimization.templates") / f"topology_{params['model']}.top"
TOPOLOGY = template_path.read_text()
template_path = files("polyamorphism_optimization.templates") / "mdp_parameters.mdp"
MDP_PARAMETERS = template_path.read_text()
# Write files
Path("mdp_parameters.mdp").write_text(MDP_PARAMETERS)
Path("topology.top").write_text(TOPOLOGY)
script_dir = Path(__file__).parent
subprocess.run([script_dir / "create_emin.sh"], check=True)
subprocess.run([script_dir / "create_annealing1.sh"], check=True)
print(f"finished and simulation directory {directory} created and filled")
for f in os.listdir(directory):
print(f)
# --- CLI entry point ---
def main():
parser = argparse.ArgumentParser(description="Create simulation input files.")
parser.add_argument("-d", "--directory", default=".", help="Base directory")
args = parser.parse_args()
create_simulation_dir(Path(args.directory))
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import sys
import configparser
from pathlib import Path
def replace_params(param_file: Path, template_file: Path, output_file: Path):
"""Replace placeholders in template_file with values from an INI file."""
config = configparser.ConfigParser()
config.optionxform = str # keep case sensitivity
config.read(param_file)
# Flatten into a simple dict {KEY: VALUE}
params = {}
for section in config.sections():
for key, value in config.items(section):
params[key] = value
content = template_file.read_text()
for key, value in params.items():
content = content.replace(key, value)
output_file.write_text(content)
def main():
if len(sys.argv) != 4:
print(f"Usage: {sys.argv[0]} PARAM_FILE TEMPLATE_FILE OUTPUT_FILE")
sys.exit(1)
param_file = Path(sys.argv[1])
template_file = Path(sys.argv[2])
output_file = Path(sys.argv[3])
replace_params(param_file, template_file, output_file)
if __name__ == "__main__":
main()

View File

@@ -1,110 +0,0 @@
#!/usr/bin/env python3
import argparse
import os
import subprocess
from pathlib import Path
# --- Template definitions ---
MDP_PARAMETERS = """\
integrator = INTEGRATOR
dt = 0.001
nsteps = NSTEPS
nstcomm = 10
nstlog = NLOG
nstcalcenergy = 10
nstenergy = NENERGY
nstxout-compressed = NSTXOUT
compressed-x-precision = 1000
energygrps = system
rlist = 1.2
nstlist = 10
coulombtype = pme
rcoulomb = 1.2
coulomb-modifier = potential-shift-verlet
vdwtype = pme
rvdw = 1.2
vdw-modifier = potential-shift-verlet
fourierspacing = 0.144
tcoupl = v-rescale
tau_t = TAUT
gen_vel = yes
gen_temp = TEMP
ref_t = TEMP
tc-grps = system
pcoupl = PCOUPL
tau_p = TAUP
ref_p = PRESSURE
compressibility = 4.5e-5
nstpcouple = 10
nsttcouple = 10
"""
PARAMS_EMIN = """\
INTEGRATOR = steep
NSTEPS = 10000
NLOG = 100
NENERGY = 100
NSTXOUT = 100
TAUT = 1.0
TEMP = 300
PCOUPL = no
TCOUPL = no
TAUP = 1.0
"""
PARAMS_AN1 = """\
INTEGRATOR = md
NSTEPS = 2000000
NLOG = 1000
NENERGY = 100
NSTXOUT = 1000
TCOUPL = v-rescale
TAUT = 0.5
TEMP = 10.0
PCOUPL = c-rescale
TAUP = 1.0
"""
TOPOLOGY = """\
[ defaults ]
; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ
1 2 yes 1.0 1.0
[atomtypes]
;name mass charge ptype sigma epsilon
A MASS 0.000 A SIGMA_A EPSILON_A
B MASS 0.000 A SIGMA_B EPSILON_B
D 0 0.000 D 0.0 0.0
...
"""
# --- Core function ---
def create_simulation_dir(directory: Path):
directory.mkdir(parents=True, exist_ok=True)
os.chdir(directory)
# Write files
(directory / "mdp_parameters.mdp").write_text(MDP_PARAMETERS)
(directory / "params_emin.ini").write_text(PARAMS_EMIN)
(directory / "params_an1.ini").write_text(PARAMS_AN1)
(directory / "topology.top").write_text(TOPOLOGY)
# ... add the rest of your templates here ...
script_dir = Path(__file__).parent
subprocess.run([script_dir / "create_emin.sh"], check=True)
subprocess.run([script_dir / "create_annealing1.sh"], check=True)
print(f"finished and simulation directory {directory} created and filled")
for f in os.listdir(directory):
print(f)
# --- CLI entry point ---
def main():
parser = argparse.ArgumentParser(description="Create simulation input files.")
parser.add_argument("-d", "--directory", default=".", help="Base directory")
args = parser.parse_args()
create_simulation_dir(Path(args.directory))
if __name__ == "__main__":
main()

View File

@@ -1,182 +0,0 @@
#!/bin/bash -l
usage() { echo "Usage: $0 [-d basedirectory ]" 1>&2; exit 1; }
DIRECTORY="."
while getopts "d:" opt; do
case $opt in
d )
DIRECTORY=$OPTARG
;;
h )
usage
;;
\? )
usage
;;
esac
done
cd $DIRECTORY
#=====================================================================================
cat > mdp_parameters.mdp << EOF
integrator = INTEGRATOR
dt = 0.001
nsteps = NSTEPS
nstcomm = 10
nstlog = NLOG
nstcalcenergy = 10
nstenergy = NENERGY
nstxout-compressed = NSTXOUT
compressed-x-precision = 1000
energygrps = system
rlist = 1.2
nstlist = 10
coulombtype = pme
rcoulomb = 1.2
coulomb-modifier = potential-shift-verlet
vdwtype = pme
rvdw = 1.2
vdw-modifier = potential-shift-verlet
fourierspacing = 0.144
tcoupl = v-rescale
tau_t = TAUT
gen_vel = yes
gen_temp = TEMP
ref_t = TEMP
tc-grps = system
pcoupl = PCOUPL
tau_p = TAUP
ref_p = PRESSURE
compressibility = 4.5e-5
nstpcouple = 10
nsttcouple = 10
EOF
#=====================================================================================
cat > params_emin.ini << EOF
INTEGRATOR = steep
NSTEPS = 10000
NLOG = 100
NENERGY = 100
NSTXOUT = 100
TAUT = 1.0
TEMP = 300
PCOUPL = no
TCOUPL = no
TAUP = 1.0
EOF
cat > params_an1.ini << EOF
INTEGRATOR = md
NSTEPS = 2000000
NLOG = 1000
NENERGY = 100
NSTXOUT = 1000
TCOUPL = v-rescale
TAUT = 0.5
TEMP = 10.0
PCOUPL = c-rescale
TAUP = 1.0
EOF
#=====================================================================================
cat > topology.top << EOF
[ defaults ]
; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ
1 2 yes 1.0 1.0
[atomtypes]
;name mass charge ptype sigma epsilon
A MASS 0.000 A SIGMA_A EPSILON_A
B MASS 0.000 A SIGMA_B EPSILON_B
D 0 0.000 D 0.0 0.0
[moleculetype]
; name nrexcl
L 1
[atoms]
; nr type resnr residu atom cgnr charge
1 A 1 L A 1 0 MASS
2 B 1 L B1 1 CHARGE_B MASS
3 B 1 L B2 1 CHARGE_B MASS
4 D 1 L D 1 CHARGE_A 0.0
[settles]
;i funct doh dhh
1 1 D_AB D_BB
[dummies3]
; Dummy from funct a b
4 1 2 3 1 DUMMY_AB DUMMY_AB
[exclusions]
1 2 3 4
2 1 3 4
3 1 2 4
4 1 2 3
[system]
MODEL
[molecules]
L NMOL
EOF
cat > topology_atomistic.top << EOF
[ defaults ]
; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ
1 2 yes 1.0 1.0
[atomtypes]
;name mass charge ptype sigma epsilon
A MASS 0.000 A SIGMA_A EPSILON_A
B MASS 0.000 A SIGMA_B EPSILON_B
[moleculetype]
; name nrexcl
A 1
[atoms]
; nr type resnr residu atom cgnr charge
1 A 1 L A 1 CHARGE_A MASS
[moleculetype]
; name nrexcl
B 1
[atoms]
; nr type resnr residu atom cgnr charge
1 B 1 L B 1 CHARGE_B MASS
[system]
MODEL
[molecules]
A 1000
B 2000
EOF
#=====================================================================================
echo $(dirname $0)
bash ".$(dirname $0)/create_emin.sh"
bash ".$(dirname $0)/create_annealing1.sh"
#=====================================================================================
echo "finished and simulation directory $DIRECTORY created and filled"
ls
exit 0

View File

@@ -0,0 +1,9 @@
INTEGRATOR = md
NSTEPS = 2000000
NLOG = 1000
NENERGY = 100
NSTXOUT = 1000
TCOUPL = v-rescale
TAUT = 1.0
PCOUPL = c-rescale
TAUP = 1.0

View File

@@ -0,0 +1,9 @@
INTEGRATOR = md
NSTEPS = 2000000
NLOG = 1000
NENERGY = 100
NSTXOUT = 1000
TCOUPL = v-rescale
TAUT = 1.0
PCOUPL = no
TAUP = 1.0

View File

@@ -0,0 +1,31 @@
integrator = INTEGRATOR
dt = 0.001
nsteps = NSTEPS
nstcomm = 10
nstlog = NLOG
nstcalcenergy = 10
nstenergy = NENERGY
nstxout-compressed = NSTXOUT
compressed-x-precision = 1000
energygrps = system
rlist = 1.2
nstlist = 10
coulombtype = pme
rcoulomb = 1.2
coulomb-modifier = potential-shift-verlet
vdwtype = pme
rvdw = 1.2
vdw-modifier = potential-shift-verlet
fourierspacing = 0.144
tcoupl = v-rescale
tau_t = TAUT
gen_vel = yes
gen_temp = TEMP
ref_t = TEMP
tc-grps = system
pcoupl = PCOUPL
tau_p = TAUP
ref_p = PRESSURE
compressibility = 4.5e-5
nstpcouple = 10
nsttcouple = 10

View File

@@ -0,0 +1,10 @@
INTEGRATOR = md
NSTEPS = 2000000
NLOG = 1000
NENERGY = 100
NSTXOUT = 1000
TCOUPL = v-rescale
TAUT = 0.5
TEMP = 10.0
PCOUPL = c-rescale
TAUP = 1.0

View File

@@ -0,0 +1,10 @@
INTEGRATOR = md
NSTEPS = 5000000
NLOG = 1000
NENERGY = 100
NSTXOUT = 1000
TCOUPL = v-rescale
TAUT = 0.5
TEMP = 10.0
PCOUPL = c-rescale
TAUP = 1.0

View File

@@ -0,0 +1,10 @@
INTEGRATOR = steep
NSTEPS = 10000
NLOG = 100
NENERGY = 100
NSTXOUT = 100
TAUT = 1.0
TEMP = 300
PCOUPL = no
TCOUPL = no
TAUP = 1.0

View File

@@ -4,17 +4,18 @@
#SBATCH --ntasks=1 #SBATCH --ntasks=1
#SBATCH --cpus-per-task=8 #SBATCH --cpus-per-task=8
#SBATCH --gres=gpu:1 #SBATCH --gres=gpu:1
#SBATCH --exclude=linux-05,linux-08,linux-02,linux-03,linux-04,linux-07 ##SBATCH --exclude=linux-05,linux-06,linux-07,linux-08
#if [ "$(gmx --version | grep "GROMACS version")" != GROMACS*2025.2* ] ; then #if [ "$(gmx --version | grep "GROMACS version")" != GROMACS*2023.3* ] ; then
# echo "Version loaded is not 2025.2! Exiting!" # echo "Version loaded is not 2023.3! Exiting!"
# exit 1 # exit 1
#fi #fi
PHYS_CORES=$(lscpu | awk -F: '/Core\(s\) per socket/ {print $2+0}')
if [ -n "$SLURM_CPUS_PER_TASK" ]; then if [ -n "$SLURM_CPUS_PER_TASK" ]; then
NT="-nt $SLURM_CPUS_PER_TASK" NT="-nt $SLURM_CPUS_PER_TASK"
elif [ $(nproc) -lt 9 ] ; then elif [ "$PHYS_CORES" -lt 9 ] ; then
NT="-nt $(nproc)" NT="-nt $PHYS_CORES"
else else
NT="-nt 8" NT="-nt 8"
fi fi
@@ -29,7 +30,7 @@ mkdir -p "$WORKDIR/out"
export GMX_MAXCONSTRWARN=-1; export GMX_MAXCONSTRWARN=-1;
gmx -nobackup grompp \ gmx -nobackup grompp \
-f $WORKDIR/mdp_parameters.mdp \ -f $WORKDIR/mdp_parameters.mdp \
-o $WORKDIR/tpr_run.tpr \ -o $WORKDIR/out/tpr_run.tpr \
-c $WORKDIR/gro_start.gro \ -c $WORKDIR/gro_start.gro \
-r $WORKDIR/gro_start.gro \ -r $WORKDIR/gro_start.gro \
-p $WORKDIR/topology.top \ -p $WORKDIR/topology.top \
@@ -42,7 +43,7 @@ if [ $? != 0 ] ; then
fi fi
gmx mdrun \ gmx mdrun \
-s $WORKDIR/tpr_run.tpr \ -s $WORKDIR/out/tpr_run.tpr \
-o $WORKDIR/out/trr_traj.trr \ -o $WORKDIR/out/trr_traj.trr \
-c $WORKDIR/out/out.gro \ -c $WORKDIR/out/out.gro \
-x $WORKDIR/out/xtc_traj.xtc \ -x $WORKDIR/out/xtc_traj.xtc \

View File

@@ -0,0 +1,33 @@
[ defaults ]
; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ
1 2 yes 1.0 1.0
[atomtypes]
;name mass charge ptype sigma epsilon
A MASS 0.000 A SIGMA_A EPSILON_A
B MASS 0.000 A SIGMA_B EPSILON_B
[moleculetype]
; name nrexcl
L 1
[atoms]
; nr type resnr residu atom cgnr charge
1 A 1 L A 1 CHARGE_A MASS
2 B 1 L B1 1 CHARGE_B MASS
3 B 1 L B2 1 CHARGE_B MASS
[settles]
;i funct doh dhh
1 1 D_AB D_BB
[exclusions]
1 2 3
2 1 3
3 1 2
[system]
MODEL
[molecules]
L NMOL

View File

@@ -0,0 +1,40 @@
[ defaults ]
; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ
1 2 yes 1.0 1.0
[atomtypes]
;name mass charge ptype sigma epsilon
A MASS 0.000 A SIGMA_A EPSILON_A
B MASS 0.000 A SIGMA_B EPSILON_B
D 0 0.000 D 0.0 0.0
[moleculetype]
; name nrexcl
L 1
[atoms]
; nr type resnr residu atom cgnr charge
1 A 1 L A 1 0 MASS
2 B 1 L B1 1 CHARGE_B MASS
3 B 1 L B2 1 CHARGE_B MASS
4 D 1 L D 1 CHARGE_A 0.0
[settles]
;i funct doh dhh
1 1 D_AB D_BB
[dummies3]
; Dummy from funct a b
4 1 2 3 1 DUMMY_AB DUMMY_AB
[exclusions]
1 2 3 4
2 1 3 4
3 1 2 4
4 1 2 3
[system]
MODEL
[molecules]
L NMOL

View File

@@ -0,0 +1,31 @@
[ defaults ]
; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ
1 2 yes 1.0 1.0
[atomtypes]
;name mass charge ptype sigma epsilon
A MASS 0.000 A SIGMA_A EPSILON_A
B MASS 0.000 A SIGMA_B EPSILON_B
[moleculetype]
; name nrexcl
A 1
[atoms]
; nr type resnr residu atom cgnr charge
1 A 1 L A 1 CHARGE_A MASS
[moleculetype]
; name nrexcl
B 1
[atoms]
; nr type resnr residu atom cgnr charge
1 B 1 L B 1 CHARGE_B MASS
[system]
MODEL
[molecules]
A NMOL
B NMOLB

View File

@@ -17,7 +17,7 @@ dependencies = [
] ]
[project.scripts] [project.scripts]
po_setup_sim = "polyamorphism_optimization.setup_sim:main" po_init_sim = "polyamorphism_optimization.innitialize_sim:main"
[tool.setuptools.package-data] [tool.setuptools.package-data]
polyamorphism_optimization = ["templates/*"] polyamorphism_optimization = ["templates/*"]