type in init; emin to python
This commit is contained in:
0
polyamorphism_optimization/annealing.py
Normal file → Executable file
0
polyamorphism_optimization/annealing.py
Normal file → Executable file
@@ -1,35 +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="00_em"
|
|
||||||
|
|
||||||
|
|
||||||
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_emin.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 "$(dirname $0)/templates/gro_$(get_ini_value params.ini params model).gro" "$simdir/gro_start.gro"
|
|
||||||
|
|
||||||
echo "emstep = 0.001" >> $simdir/mdp_parameters.mdp
|
|
||||||
|
|
||||||
|
|
36
polyamorphism_optimization/emin.py
Executable file
36
polyamorphism_optimization/emin.py
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
from replace_params import replace_params
|
||||||
|
|
||||||
|
|
||||||
|
def main(root_dir: Path):
|
||||||
|
simdir = root_dir / "00_em"
|
||||||
|
|
||||||
|
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_emin.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")
|
||||||
|
|
||||||
|
# Add finer emstep
|
||||||
|
with (simdir / "mdp_parameters.mdp").open("a") as f:
|
||||||
|
f.write("\n")
|
||||||
|
f.write("emstep = 0.001")
|
||||||
|
|
||||||
|
print(f"Energy minimization 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]))
|
@@ -6,9 +6,12 @@ from pathlib import Path
|
|||||||
from importlib.resources import files
|
from importlib.resources import files
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
|
from annealing import main as annealing
|
||||||
|
from emin import main as emin
|
||||||
|
|
||||||
|
|
||||||
# --- Core function ---
|
# --- Core function ---
|
||||||
def innitialize_simulation_dir(directory: Path):
|
def initialize_simulation_dir(directory: Path):
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
|
|
||||||
params = configparser.ConfigParser()
|
params = configparser.ConfigParser()
|
||||||
@@ -23,9 +26,8 @@ def innitialize_simulation_dir(directory: Path):
|
|||||||
Path("mdp_parameters.mdp").write_text(MDP_PARAMETERS)
|
Path("mdp_parameters.mdp").write_text(MDP_PARAMETERS)
|
||||||
Path("topology.top").write_text(TOPOLOGY)
|
Path("topology.top").write_text(TOPOLOGY)
|
||||||
|
|
||||||
script_dir = Path(__file__).parent
|
emin(directory)
|
||||||
subprocess.run([script_dir / "create_emin.sh"], check=True)
|
annealing(directory)
|
||||||
subprocess.run([script_dir / "create_annealing1.sh"], check=True)
|
|
||||||
|
|
||||||
print(f"finished and simulation directory {directory} created and filled")
|
print(f"finished and simulation directory {directory} created and filled")
|
||||||
for f in os.listdir(directory):
|
for f in os.listdir(directory):
|
0
polyamorphism_optimization/replace_params.py
Normal file → Executable file
0
polyamorphism_optimization/replace_params.py
Normal file → Executable file
@@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [[ $# -lt 2 ]]; then
|
|
||||||
echo "Usage: $0 <params.ini> <template> [--output <output_file>]"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PARAMS_FILE="$1"
|
|
||||||
TEMPLATE_FILE="$2"
|
|
||||||
OUTPUT_FILE="${TEMPLATE_FILE}.out"
|
|
||||||
|
|
||||||
# Optional --output <filename>
|
|
||||||
if [[ "$3" == "--output" && -n "$4" ]]; then
|
|
||||||
OUTPUT_FILE="$4"
|
|
||||||
fi
|
|
||||||
|
|
||||||
declare -A PARAMS
|
|
||||||
|
|
||||||
# Load params.ini (ignore [section] headers)
|
|
||||||
while IFS='=' read -r key value; do
|
|
||||||
# Trim whitespace and ignore comments/sections
|
|
||||||
key="${key%%\#*}" # remove inline comments
|
|
||||||
value="${value%%\#*}"
|
|
||||||
key="$(echo "$key" | xargs)" # trim leading/trailing whitespace
|
|
||||||
value="$(echo "$value" | xargs)"
|
|
||||||
[[ -z "$key" || "$key" =~ ^\[.*\]$ ]] && continue
|
|
||||||
|
|
||||||
key_upper=$(echo "$key" | tr '[:lower:]' '[:upper:]')
|
|
||||||
PARAMS["$key_upper"]="$value"
|
|
||||||
done < "$PARAMS_FILE"
|
|
||||||
|
|
||||||
# Read template into a variable
|
|
||||||
template=$(<"$TEMPLATE_FILE")
|
|
||||||
|
|
||||||
# Replace placeholders (only when surrounded by spaces)
|
|
||||||
for key in "${!PARAMS[@]}"; do
|
|
||||||
val="${PARAMS[$key]}"
|
|
||||||
# Use sed to do space-surrounded substitution
|
|
||||||
template=$(echo "$template" | sed -E "s/([[:space:]])$key([[:space:]])/$val/g")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Save to output file
|
|
||||||
echo "$template" > "$OUTPUT_FILE"
|
|
||||||
echo "Wrote output to $OUTPUT_FILE"
|
|
||||||
|
|
@@ -17,7 +17,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
po_init_sim = "polyamorphism_optimization.innitialize_sim:main"
|
po_init_sim = "polyamorphism_optimization.initialize_sim:main"
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
polyamorphism_optimization = ["templates/*"]
|
polyamorphism_optimization = ["templates/*"]
|
||||||
|
Reference in New Issue
Block a user