Coverage for examples/write_to_lammps.py: 95%
20 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1""" Example of writing a configuration to a LAMMPS dump file. """
2import os
4import gamdpy as gp
6# Setup configuration: FCC Lattice
7configuration = gp.Configuration(D=3)
8configuration.make_lattice(gp.unit_cells.FCC, cells=[8, 8, 8], rho=0.973)
9configuration['m'] = 1.0
10configuration.randomize_velocities(temperature=0.7)
12# Write initial configuration to LAMMPS dump file
13lmp_dump = gp.configuration_to_lammps(configuration)
14print(lmp_dump, file=open('dump.initial', 'w'))
16# Setup pair potential: Single component 12-6 Lennard-Jones
17pair_func = gp.apply_shifted_potential_cutoff(gp.LJ_12_6_sigma_epsilon)
18sig, eps, cut = 1.0, 1.0, 2.5
19pair_pot = gp.PairPotential(pair_func, params=[sig, eps, cut], max_num_nbs=1000)
21# Setup integrator: NVT
22integrator = gp.integrators.NVT(temperature=0.7, tau=0.2, dt=0.005)
24# Setup runtime actions, i.e. actions performed during simulation of timeblocks
25runtime_actions = [gp.TrajectorySaver(),
26 gp.ScalarSaver(),
27 gp.MomentumReset(100)]
30# Setup Simulation.
31sim = gp.Simulation(configuration, pair_pot, integrator, runtime_actions,
32 num_timeblocks=100, steps_per_timeblock=1000,
33 storage='memory')
35# Delete old dump file if it exists
36dump_filename = 'dump.lammps'
37if os.path.exists(dump_filename):
38 os.remove(dump_filename)
40# Run simulation and write configuration to LAMMPS dump file on the fly
41for block in sim.run_timeblocks():
42 lmp_dump = gp.configuration_to_lammps(sim.configuration, timestep=sim.steps_per_block*block)
43 print(lmp_dump, file=open(dump_filename, 'a'))
45# Open dump file in ovito with
46# ovito dump.lammps
47#
48# Open in VMD with
49# vmd -lammpstrj dump.lammps