Coverage for examples/hydrocorr.py: 100%
18 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 how to calculate the two hydrodynamic correlation functions
3 1: the transverse current correlation function (jacf), and
4 2: the longitudinal density correlation function (dacf)
6 The system is a simple Lennard-Jones system at the liquid state point.
8 The correlation functions are stored in the files jacf.dat and dacf.dat when calling the calculator read method
9 1st column is time, remaining columns are correlation function values at the different wavevectors k = 2*pi*n/L
10 where n is the wave number and L the system box length in the x-direction.
12 It is recommended to use a simple cubic box for these calculations.
14 """
16import gamdpy as gp
17import os
19# Setup configuration: FCC Lattice
20configuration = gp.Configuration(D=3, compute_flags={'W':True})
21configuration.make_lattice(gp.unit_cells.FCC, cells=[8, 8, 8], rho=0.8)
22configuration['m'] = 1.0
23configuration.randomize_velocities(temperature=0.9)
25# Setup pair potential: Single component 12-6 Lennard-Jones
26pair_func = gp.apply_shifted_potential_cutoff(gp.LJ_12_6_sigma_epsilon)
27sig, eps, cut = 1.0, 1.0, 2.5
28pair_pot = gp.PairPotential(pair_func, params=[sig, eps, cut], max_num_nbs=1000)
30# Setup integrator: NVT
31integrator = gp.integrators.NVT(temperature=0.9, tau=0.2, dt=0.005)
33# Setup runtime actions, i.e. actions performed during simulation of timeblocks
34runtime_actions = [gp.TrajectorySaver(),
35 gp.ScalarSaver(16, {'W':True}),
36 gp.MomentumReset(100)]
38# Setup Simulation.
39sim = gp.Simulation(configuration, pair_pot, integrator, runtime_actions,
40 num_timeblocks=2048, steps_per_timeblock=32,
41 storage='memory')
43print('Simulation created')
45hydrocorr = gp.CalculatorHydrodynamicCorrelations(configuration, dtsample=32*0.005, nwaves=10)
47# Run simulation
48for _ in sim.run_timeblocks():
49 hydrocorr.update()
51print(sim.summary())
53hydrocorr.read()