Attribute error

Hi,

When I am running an ase model, I am getting an error saying, ‘Atoms’ object no attribute ‘get_charges’.

Can someone please advise me on it? Please find below the error message.

Regards,
Swayam

[[email protected] tests]$ python test_ase_kim.py
modelname=‘ex_model_Ar_P_Morse’
lattice constant=4
test_ase_kim.py:20: UserWarning: Use ase.build.bulk() instead
slab = bulk(‘Ar’, ‘fcc’, a=lattice_constant)
Traceback (most recent call last):
File “test_ase_kim.py”, line 21, in
slab.set_calculator(calc)
File “/users/sswayamj/ase/ase/atoms.py”, line 243, in set_calculator
calc.set_atoms(self)
File “/gpfs/runtime/opt/openkim/1.8.2/lib/python2.7/site-packages/kimcalculator.py”, line 155, in set_atoms
self.init_kim(atoms)
File “/gpfs/runtime/opt/openkim/1.8.2/lib/python2.7/site-packages/kimcalculator.py”, line 174, in init_kim
self.make_test_string(atoms)
File “/gpfs/runtime/opt/openkim/1.8.2/lib/python2.7/site-packages/kimcalculator.py”, line 231, in make_test_string
self.teststring = make_kimscript(tmp_name, self.modelname, atoms)
File “/gpfs/runtime/opt/openkim/1.8.2/lib/python2.7/site-packages/kimcalculator.py”, line 442, in make_kimscript
if atoms.get_charges().any():
AttributeError: ‘Atoms’ object has no attribute ‘get_charges’

Hi Swayam,

I know you raised this issue weeks ago, so I’m sorry for not having already resolved it by now. Can you please post the script you’re trying to run?

Thanks,
Dan

Hi Dan,

Thanks for your reply. Please find below the script:

#!/usr/bin/env python
“”"
ASE cohesive energy example test with dependencies

Author: Matt Bierbaum
“”"
from ase.lattice import bulk
from kimcalculator import KIMCalculator
from string import Template
import os

#grab from stdin (or a file)
model = raw_input(“modelname=”)
lattice_constant = raw_input(“lattice constant=”)
lattice_constant = 10**10 * float(lattice_constant)

calculate the cohesive energy

calc = KIMCalculator(model)
slab = bulk(‘Ar’, ‘fcc’, a=lattice_constant)
slab.set_calculator(calc)
energy = -slab.get_potential_energy()

pack the results in a dictionary

results = {‘lattice_constant’: lattice_constant,
‘cohesive_energy’: energy}

output = Template("""
[{
“property-id” “tag:[email protected],2014-04-15:property/cohesive-potential-energy-cubic-crystal”
“instance-id” 1
“short-name” {
“source-value” [“fcc”]
}
“species” {
“source-value” [“Ar”]
}
“a” {
“source-value” $lattice_constant
“source-unit” “angstrom”
}
“basis-atom-coordinates” {
“source-value” [[0.0 0.0 0.0] [0.0 0.5 0.5] [0.5 0.0 0.5] [0.5 0.5 0.0]]
}
“space-group” {
“source-value” “Fm-3m”
}
“cohesive-potential-energy” {
“source-value” $cohesive_energy
“source-unit” “eV”
}
}]""").substitute(**results)

with open(os.path.abspath(“output/results.edn”), “w”) as f:
f.write(output)

Regards,
Swayam