121
General Questions and Answers / Re: Chemical potential and molecular dynamics
« on: December 15, 2015, 16:58 »
Yes, that is possible using a hook function during Molecular Dynamics.
To do so, you first have to define a suitable hook function in your script, e.g.
Then, you define your MD simulation as usual, but with the additional argument
e.g.
The hook function will now be called after each MD step and the specified operation, in this case the calculation and printing of the chemical potential, will be performed.
Of course, the calculator that you use for running molecular dynamics must support the calculation of the chemical potential (i.e. it must be an electronic-structure-based calculator such as the LCAOCalculator, as this is the electronic chemical potential).
To do so, you first have to define a suitable hook function in your script, e.g.
Code
def chemical_potential_hook(step, time, configuration):
"""
Hook function to calculate and print the chemical potential at
every MD step.
"""
chemical_potential = ChemicalPotential(configuration)
nlprint(chemical_potential)
Then, you define your MD simulation as usual, but with the additional argument
Code
post_step_hook=chemical_potential_hook
e.g.
Code
md_trajectory = MolecularDynamics(
bulk_configuration,
trajectory_filename='trajectory.nc',
steps=100000,
log_interval=2,
post_step_hook=chemical_potential_hook,
method=method
)
Of course, the calculator that you use for running molecular dynamics must support the calculation of the chemical potential (i.e. it must be an electronic-structure-based calculator such as the LCAOCalculator, as this is the electronic chemical potential).