QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: ramkrishna on October 18, 2016, 19:05

Title: MD with electric field
Post by: ramkrishna on October 18, 2016, 19:05
Hi,
Is it possible to execute MD under electric field in ATK?

Thanks
Ramkrishna
Title: Re: MD with electric field
Post by: Daniele Stradi on October 19, 2016, 09:15
Which kind of MD? Classical or Quantum (DFT, Tight-Binding)? For the latter, there is no technical limitation about running dynamics including an E-field.
Title: Re: MD with electric field
Post by: ramkrishna on October 19, 2016, 18:44
Hi Daniele,
Thank you for your reply. Is there any possibility for the classical potentials?

Thanks
Ramkrishna
Title: Re: MD with electric field
Post by: Julian Schneider on October 20, 2016, 10:59
Yes, you can do this using a hook function, in this case a 'post-step-hook', because you want to modify the forces acting on the partticles (see http://docs.quantumwise.com/manuals/Types/MolecularDynamics/MolecularDynamics.html#moleculardynamics-f)

First you set up your MD simulation as ususal. Send the simulation to the Editor to get the python script.
You need to modify your script as shown in the attached example script.
First you need to specify the charges of the atoms.
If you are using a potential that uses electrostatics, you can use the partial charges defined in the potential by using the PartialCharges analysis object.
However, you can also define any other arbitrary partial charges on the atoms.
Code
partial_charges = PartialCharges(bulk_configuration).evaluate()

# If the potential does not define partial charges, you can define charges yourself.
# Note that they only will be used to interact with the external electric field.
# e.g. partial_charges = [0.5, 0.5, -0.5, -0.5, ...]*elementary_charge

Then you need to define an electric field, which has the units Volt/Meter or Volt/Ang, etc.
Code
# Define the electric field.
field = [0.0, 0.0, 1.0]*Volt/nm

Then you need to define a hook class, which adds the forces due to the electric field i.e. F=q*E to the vector of atomic forces.
Create an object of this class that will be passed to the MolecularDynamics function.
Code
class ElectricFieldHook(object):
def __init__(self, charges, electric_field):
# Store the charges and the electric field.
charges = charges.reshape(-1, 1)
field = electric_field.reshape(1, 3)
self.efield_forces = (charges*field).convertTo(eV/Ang)

def __call__(self, step, time, configuration, forces, stress):
        # Add the electric field forces to the forces vector.
forces += self.efield_forces

electric_field_hook = ElectricFieldHook(
    charges=partial_charges,
    electric_field=field
)

This hook object needs to be passed as post_step_hook to the MolecularDynamics function.
Code
md_trajectory = MolecularDynamics(
    bulk_configuration,
    constraints=[],
    trajectory_filename='efield_trajectory.nc',
    steps=2000,
    log_interval=20,
    post_step_hook=electric_field_hook,
    method=method
)
Title: Re: MD with electric field
Post by: ramkrishna on October 21, 2016, 00:11
Hello Julian ,
Thank you very much for the script. It will certainly help me a lot. If I find any difficulty in running the script, I will let you know.

Thanks
Ramkrishna