[ase-users] Questions regarding the calculate() method

Kondov, Ivan (SCC) ivan.kondov at kit.edu
Tue Jan 16 15:13:34 CET 2018


Dear all,

I want to do a geometry optimization and get back the optimized structure,
the energy and the forces. Here is an example:

from ase.build import molecule
from ase.calculators.nwchem import NWChem
atoms = molecule('NH3')
calc = NWChem(task='optimize', xc='pbe0')
atoms.set_calculator(calc)
print(atoms.get_positions())
calc.calculate(atoms)
print(print(atoms.get_potential_energy()))
print(atoms.get_positions())
print(atoms.get_forces())

[[ 0.        0.        0.116489]
 [ 0.        0.939731 -0.271808]
 [ 0.813831 -0.469865 -0.271808]
 [-0.813831 -0.469865 -0.271808]]
-1528.1988692333646
[[ 0.        0.        0.116489]
 [ 0.        0.939731 -0.271808]
 [ 0.813831 -0.469865 -0.271808]
 [-0.813831 -0.469865 -0.271808]]
[[ -1.02844134e-04   1.54266201e-04  -2.41683715e-03]
 [  5.14220671e-05   1.54266201e-04   8.22753073e-04]
 [  3.08532403e-04  -1.54266201e-04   7.71331006e-04]
 [ -2.05688268e-04  -1.54266201e-04   8.22753073e-04]]

The energy and the forces are correct but not the structure (it should be
updated). 

1) The reason for this behavior is that Calculator.calculate()  works on a
copy of the atoms object if it has been supplied as argument:

if atoms is not None:
    self.atoms = atoms.copy()

Is this the wished behavior? Because the only way to get to the updated
atoms object is then using this detour: calc.atoms.get_positions() in the
user function. 

2) Then the solution would be to simply not specify the atoms in the call:

calc.calculate()

Then it will work on the atoms object associated with the set_calculator()
method. Unfortunately, then I get the error:

    calc.calculate()
  File " /ase/calculators/calculator.py", line 644, in calculate
    self.write_input(self.atoms, properties, system_changes)
  File " /ase/calculators/nwchem.py", line 75, in write_input
    p.initial_magmoms = atoms.get_initial_magnetic_moments().tolist()
AttributeError: 'NoneType' object has no attribute
'get_initial_magnetic_moments'

The reason is that write_input() is called with self.atoms that is None.
Obviously the calculator does not have atoms object although
atoms.set_calculator(calc) was called. This is because NWChem class has no
set_atoms() method. Should we write this one?

I tend to first fix the issue number (2). What about the first issue?

I will appreciate your feedback very much.

Best regards,
Ivan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 7554 bytes
Desc: not available
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20180116/9a4d50a2/attachment-0001.p7s>


More information about the ase-users mailing list