Coverage for examples/evaluator_inverse_powerlaw.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1""" Simulate Lennard-Jones system and evaluate the inverse power law potential.  

2 

3In this example, we simulate a Lennard-Jones system. 

4For the last configuration after each timeblock, 

5we evaluate the r**-12 inverse power law potential (IPL), 

6and compute the mean. 

7 

8""" 

9 

10import numpy as np 

11 

12import gamdpy as gp 

13 

14# Setup configuration: FCC Lattice 

15configuration = gp.Configuration(D=3) 

16configuration.make_lattice(gp.unit_cells.FCC, cells=[8, 8, 8], rho=0.973) 

17configuration['m'] = 1.0 

18configuration.randomize_velocities(temperature=0.7) 

19 

20# Setup pair potential: Single component 12-6 Lennard-Jones 

21pair_func = gp.apply_shifted_potential_cutoff(gp.LJ_12_6_sigma_epsilon) 

22pair_pot = gp.PairPotential(pair_func, params=[1.0, 1.0, 2.5], max_num_nbs=1000) 

23 

24# Setup integrator: NVT 

25integrator = gp.integrators.NVT(temperature=0.7, tau=0.2, dt=0.005) 

26 

27# Setup runtime actions, i.e. actions performed during simulation of timeblocks 

28runtime_actions = [gp.TrajectorySaver(), 

29 gp.ScalarSaver(16), 

30 gp.MomentumReset(100)] 

31 

32 

33# Setup Simulation. 

34sim = gp.Simulation(configuration, pair_pot, integrator, runtime_actions, 

35 num_timeblocks=32, 

36 steps_per_timeblock=2048, 

37 storage='memory') 

38 

39# Create evaluator for the inverse power law potential (IPL) 

40# (replace with your potential of interest) 

41pair_func_ref = gp.apply_shifted_potential_cutoff(gp.LJ_12_6) 

42ipl12 = gp.PairPotential(pair_func_ref, params=[4.0, 0.0, 2.5], max_num_nbs=1000) 

43evaluator = gp.Evaluator(sim.configuration, ipl12) 

44 

45# Run simulation 

46u_ipl = [] 

47for block in sim.run_timeblocks(): 

48 evaluator.evaluate(sim.configuration) # Evaluate IPL for final configuration of timeblock 

49 u_ipl.append(np.sum(evaluator.configuration['U'])) 

50 

51print(f'Mean IPL potential energy: {np.mean(u_ipl)}') 

52