PropertyNotImplementedError while running openkim

Dear openkim users,

I have an error while running a python script on openkim, it says,

raise PropertyNotImplementedError
ase.calculators.calculator.PropertyNotImplementedError

could u please look into the error below and suggest a solution.

Thanks,

Swayam

[[email protected] ase_calculator]$ python test_ase_kim.py
Traceback (most recent call last):
File “test_ase_kim.py”, line 13, in
ar.set_calculator(calc1)
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():
File “/users/sswayamj/ase/ase/atoms.py”, line 642, in get_charges
raise PropertyNotImplementedError
ase.calculators.calculator.PropertyNotImplementedError

Hi Swayam,

Can you provide some more information? What computing system are you using? How is it setup with components from openkim? What is the python/ase script your are trying to execute? Anything else you think might be helpful for us while we try to diagnose your problem and help you resolve it.

Thanks,

Ryan

Dear Swayam and Ryan,

I do not know for sure, but it looks like this could be related to a relatively recent change in ASE. ASE used to throw a NotImplementedError (or occasionally an AttributeError) if you tried to get a quantity from the atoms that the atoms do not have and the calculator cannot calculate the property. Scripts can then catch this error and handle it accordingly. Unfortunately, the NotImplementedError might be raised by other things, and a real error would then be caught by the script as well, and handled incorrectly. For that reason, ASE was changed so it now raises its own PropertyNotImplementedError in these cases, so you only catch these and not other NotImplementedError conditions.

Maybe there is a mismatch between kimcalculator and ASE; either kimcalculator has not been updated to reflect this, or kimcalculator has been updated but is used with an older ASE.

This is just a wild guess.

Best regards

Jakob

Hello all,

Thought I’d pop in and explain: the ASE calculator was originally developed for internal use so it mainly provided the functionality used by our group. Therefore, I accidentally omitted the get_charges() function. To implement we need a line like this (https://github.com/mattbierbaum/openkim-kimcalculator-ase/blob/master/kimcalculator.py#L199) for charges, as well as a get_charges like this (https://github.com/mattbierbaum/openkim-kimcalculator-ase/blob/master/kimcalculator.py#L315) which returns those values. I don’t have a working system at the moment but I would happily accept a patch if someone verifies that this works.

If there are any other quantities missing let me know

-Matt

Hi Matt,

Any idea if we have patch for it now, and if there is a timeline for it?

thanks,
swayam

There is, indeed, a missing get_charges function in kimcalculator which can be added much like similar functions. For instance, you could add:

def get_charges(self, atoms):
if not self.manual_update_only:
self.update(atoms)
if self.km_particleCharge is not None:
return self.km_particleCharge.copy()
else:
raise SupportError(“charges”)

on lines 306-312. Actually grabbing “particleCharges” from the API is actually already handled elsewhere in the module. However, this will get you an error like so if you try to go into the ‘tests’ directory of the repo and execute test_simple.py:

Traceback (most recent call last):

File “test_simple.py”, line 14, in

ar.set_calculator(calc1)

File “/usr/local/lib/python2.7/dist-packages/ase/atoms.py”, line 244, in set_calculator

calc.set_atoms(self)

File “/usr/local/lib/python2.7/dist-packages/kimcalculator.py”, line 155, in set_atoms

self.init_kim(atoms)

File “/usr/local/lib/python2.7/dist-packages/kimcalculator.py”, line 174, in init_kim

self.make_test_string(atoms)

File “/usr/local/lib/python2.7/dist-packages/kimcalculator.py”, line 231, in make_test_string

self.teststring = make_kimscript(tmp_name, self.modelname, atoms)

File “/usr/local/lib/python2.7/dist-packages/kimcalculator.py”, line 450, in make_kimscript

if atoms.get_charges().any():

File “/usr/local/lib/python2.7/dist-packages/ase/atoms.py”, line 638, in get_charges

return self._calc.get_charges(self)

File “/usr/local/lib/python2.7/dist-packages/kimcalculator.py”, line 308, in get_charges

self.update(atoms)

File “/usr/local/lib/python2.7/dist-packages/kimcalculator.py”, line 263, in update

if (self.km_numberOfAtoms[0] != natoms or

TypeError: ‘NoneType’ object has no attribute ‘getitem

The cause for this lies in the way that kimcalculator searches for the .kim file of the Model in trying to all the KIM_API_file_init function. As a temporary way to sidestep this, let’s place the KIM descriptor file I’ve attached into the ‘tests’ directory. This then gets rid of the PropertyNotImplementedError. However, it still produces a segfault! This may be due to the following note listed in the ‘TODO’ file of the repo:

KIM_API_get_index : appears to modify memory that it
does not own. atoms.get_pbc() changes from
start to end of checkIndex call.

model_driver_P_LJ.kim (4.39 KB)

Hi again Swayam,

It seems I made a stupid mistake. You’re supposed to be using the descriptor.kim file of the Test, not the Model. If, for example, you use the descriptor.kim file for ASECohesiveEnergyFromQueryExample_fcc_Ar__TE_102111117114_001 (see here), there is no segfault when running ~/tests/test_simple.py:

[email protected]:~/Documents/openkim-kimcalculator-ase/tests$ python test_simple.py
[[ 10.52 0. 0. ]
[ 0. 10.52 0. ]
[ 0. 0. 10.52]]
kim energy = -2.43259847847

The other scripts under ~/tests also run without error. I’m putting in a pull request to the openkim-kimcalculator-ase repo adding the get_charges function. Once it has been accepted, please pull the latest and place the descriptor.kim file I linked above in the directory where you’re running the script you sent me and it should work. However, I would caution that I do believe there are still segfaults somewhere in kimcalculator, at least in KIM_API_get_index as mentioned in the TODO and perhaps elsewhere, and these have not been thoroughly tracked down, so you’ll be using this at your own risk in that sense.

Dan