Skip to content

Commit e5ac5bc

Browse files
authored
Add files via upload
1 parent d90728b commit e5ac5bc

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Scripts/steer

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Command-line script to run a steered molecular dynamics simulation for protein folding.
5+
6+
This script uses native contacts (Q-value) and RMSD as collective variables
7+
to guide the folding of a protein towards its native state.
8+
"""
9+
10+
import warnings
11+
warnings.filterwarnings('ignore')
12+
13+
import argparse
14+
import os
15+
import sys
16+
import numpy as np
17+
from util import load_projection_args
18+
import MDAnalysis as mda
19+
20+
# --- Helper Classes and Functions ---
21+
22+
def main():
23+
"""
24+
Main function to parse arguments and run the folding simulation.
25+
"""
26+
parser = argparse.ArgumentParser(
27+
description="Run a steered molecular dynamics simulation for protein folding.",
28+
formatter_class=argparse.ArgumentDefaultsHelpFormatter
29+
)
30+
parser.add_argument('--start_config', type=str, required=True, help='Path to the starting (unfolded) structure file.')
31+
parser.add_argument('--trajectory', type=str, default=None, help='(Optional) Path to an input trajectory file (.xtc, .dcd) to use as the starting point.')
32+
parser.add_argument('--module_dir', type=str, default=".", help='Path to directory containing "fold.py" and "system.py".')
33+
parser.add_argument('--target_projection', type=float, nargs=2, default=[0.0, 1.0], help='Target projection values for [RMSD, Q-value].')
34+
parser.add_argument('--temperature', type=int, default=355, help='Simulation temperature in Kelvin.')
35+
parser.add_argument('--relax1', type=int, default=5, help='Number of steps for the first relaxation phase.')
36+
parser.add_argument('--relax2', type=int, default=10, help='Number of steps for the second relaxation phase.')
37+
parser.add_argument('--max_probes', type=int, default=100, help='Number of walkers for the exploration phase.')
38+
parser.add_argument('--max_cycles', type=int, default=50000, help='Number of iterations.')
39+
parser.add_argument('--no_change_threshold', type=float, default=0.01, help='Threshold for stopping if collective variables do not change.')
40+
parser.add_argument('--verbose', action='store_true', help='Enable verbose output during the simulation.')
41+
parser.add_argument('--projection_args', type=str, default="project.json", help='Path to a JSON file containing projection arguments.')
42+
args = parser.parse_args()
43+
44+
module_path = os.path.abspath(args.module_dir)
45+
sys.path.insert(0, module_path)
46+
47+
try:
48+
from fold import Steer
49+
from system import Simulation_obj
50+
from projection import project
51+
except ImportError as e:
52+
print(f"Error: Could not import 'Steer' or 'Simulation_obj' from '{module_path}'.")
53+
print(f"Details: {e}")
54+
print("Please ensure that 'fold.py' and 'system.py' are in the specified --module_dir.")
55+
sys.exit(1)
56+
57+
# for f in [args.ref_config, args.start_config]:
58+
# if not os.path.exists(f):
59+
# print(f"Error: Input file not found at '{f}'")
60+
# sys.exit(1)
61+
62+
print("--- Folding Simulation Configuration ---")
63+
print(f"Module Path: {module_path}")
64+
# print(f"Reference Config: {args.ref_config}")
65+
print(f"Start Config: {args.start_config}")
66+
print(f"Temperature: {args.temperature} K")
67+
print(f"Relaxation 1: {args.relax1} steps")
68+
print(f"Relaxation 2: {args.relax2} steps")
69+
print(f"Max Probes: {args.max_probes}")
70+
print("--------------------------------------\n")
71+
72+
print("Setting up the simulation...")
73+
74+
if args.projection_args:
75+
projection_args = load_projection_args(args.projection_args)
76+
print("Loaded projection_args from file.")
77+
else:
78+
projection_args = {}
79+
#projection_args = {}
80+
81+
if args.trajectory:
82+
universe = mda.Universe(args.start_config, args.trajectory)
83+
universe.trajectory[-1]
84+
print(f"Loading initial positions from last frame of '{args.trajectory}'.")
85+
else:
86+
universe = mda.Universe(args.start_config)
87+
print(f"Loading initial positions from '{args.start_config}'.")
88+
89+
initial_positions = universe.atoms.positions * 0.1
90+
91+
sim_obj = Simulation_obj()
92+
steer = Steer(
93+
simulation_obj=sim_obj.simulation,
94+
projection_fn=project,
95+
projection_args=projection_args,
96+
topology_file_path=args.start_config,
97+
target_projection=np.array(args.target_projection),
98+
temperature=args.temperature
99+
)
100+
print("Steering environment initialized.")
101+
102+
print("\nStarting folding simulation...")
103+
steer.move(
104+
initial_positions=initial_positions,
105+
verbose=args.verbose,
106+
relax1_steps=args.relax1,
107+
relax2_steps=args.relax2,
108+
max_probes_per_cycle = args.max_probes,
109+
max_cycles = args.max_cycles
110+
)
111+
print("\nSimulation finished.")
112+
113+
if __name__ == '__main__':
114+
main()

0 commit comments

Comments
 (0)