forked from orbital-materials/orb-models
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaClWaterMD.py
More file actions
77 lines (61 loc) · 2.2 KB
/
NaClWaterMD.py
File metadata and controls
77 lines (61 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import torch
from ase.io import read, write
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
from ase.md.langevin import Langevin
from ase import units
from ase.md import MDLogger
from orb_models.forcefield import pretrained
from orb_models.forcefield.calculator import ORBCalculator
def setup_device():
"""Set up and return the appropriate compute device."""
if torch.cuda.is_available():
device = torch.device("cuda")
else:
device = torch.device("cpu")
print(f"Using device: {device}")
return device
def run_md_simulation(
input_file: str = "NaClWater.xyz",
cell_size: float = 25.25,
temperature_K: float = 300,
timestep: float = 0.5 * units.fs,
friction: float = 0.01 / units.fs,
total_steps: int = 100,
traj_interval: int = 20,
log_interval: int = 1,
):
"""Run molecular dynamics simulation with specified parameters.
Args:
input_file: Path to input XYZ file
cell_size: Size of cubic simulation cell
temperature_K: Temperature in Kelvin
timestep: MD timestep
friction: Langevin friction coefficient
total_steps: Total number of MD steps
traj_interval: Interval for trajectory writing
log_interval: Interval for log writing
"""
# Set up device
device = setup_device()
# Read in the system from file and set the cell size and pbc
atoms = read(input_file)
atoms.set_cell([cell_size] * 3)
atoms.set_pbc([True] * 3)
# Set the calculator
atoms.calc = ORBCalculator(*pretrained.orb_v3_direct_20_omat(), device=device, compile=False)
# Set the initial velocities
MaxwellBoltzmannDistribution(atoms, temperature_K=temperature_K)
# Set the dynamics
dyn = Langevin(atoms, timestep, temperature_K=temperature_K, friction=friction)
# Define output functions and attach to dynamics
dyn.attach(
lambda: write("NaClWaterMD.xyz", atoms, append=True), interval=traj_interval
)
dyn.attach(MDLogger(dyn, atoms, "md_nvt.log"), interval=log_interval)
# Run the dynamics
dyn.run(steps=total_steps)
def main():
"""Main entry point for the script."""
run_md_simulation()
if __name__ == "__main__":
main()