[ase-users] Save SocketIOCalculator property to file

Offermans Willem willem.offermans at vito.be
Tue Jan 21 15:18:42 CET 2020


Dear Maxime and ASE friends,

Thank you for your response.

It is weird to note that the trajectory read method does not provide the
feature to reconstruct the attached calculator. This is counterintuitive,
to my opinion. I could imagine that the method needs something like
an extra ``attach_calculator=True``, but that should then do the trick.

If I follow plan B and use a database file to store the atoms objects and
attached calculator objects, I got an error upon the get_atoms method.
Note that there is also a read method, but again without reconstruction
of attached calculator object. The error is given below. It is probably due
to the used IOSocketCalculator, or am I doing something wrong??

Traceback (most recent call last):
  File "CO_GGA_PBESOL_PAW_10_10_10_FreqAnalNew2.py", line 317, in <module>
    vibImage = vibImagesDatabase.get_atoms(id=1,attach_calculator=True)
  File "/home/woffermans/.local/lib/python3.6/site-packages/ase/db/core.py", line 408, in get_atoms
    return row.toatoms(attach_calculator, add_additional_information)
  File "/home/woffermans/.local/lib/python3.6/site-packages/ase/db/row.py", line 230, in toatoms
    atoms.calc = get_calculator_class(self.calculator)(**params)
  File "/home/woffermans/.local/lib/python3.6/site-packages/ase/calculators/calculator.py", line 161, in get_calculator_class
    module = __import__('ase.calculators.' + name, {}, None, [classname])
ModuleNotFoundError: No module named 'ase.calculators.socketiocalculator'

So probably I need to think about a plan C and try the suggestions by Maxime.

To be continued ...


Met vriendelijke groeten,
Mit freundlichen Grüßen,
With kind regards,


Willem Offermans
Researcher Electrocatalysis SCT
VITO NV | Boeretang 200 | 2400 Mol
Phone:+32(0)14335263 Mobile:+32(0)492182073

Willem.Offermans at Vito.be<mailto:Willem.Offermans at Vito.be>

[cid:982BA063-B96A-4A1B-89AB-5A01CA9FC70D at vito.local]

On 21 Jan 2020, at 13:35, Maxime Van den Bossche via ase-users <ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk>> wrote:

Dear Willem,

In the piece of code you found, you can see that the calculator
information is in fact stored in the trajectory file, it's just that the
reader is returning a SinglePointCalculator with the calculation
results (instead of reconstructing the actual calculator).

So if you want to get the calculator information from a trajectory
file, you can do something like this:
"""
from ase.io<http://ase.io/> import write, ulm
from ase.calculators.emt import EMT
from ase.build import bulk

atoms = bulk('Au')
calc = EMT()
atoms.set_calculator(calc)
atoms.get_potential_energy()
write('test.traj', atoms)

backend = ulm.open('test.traj', 'r')
print(backend.calculator.get('name'))  # emt
print(backend.calculator.get('parameters'))  # {}
print(backend.calculator.get('energy'))  # 0.0026063...
"""

I don't know if there is a more elegant way currently.
At least the databases in ASE provide easier access
to the stored calculators, see:
https://wiki.fysik.dtu.dk/ase/ase/db/db.html

/Maxime



Dear ASE friends,

I dug into the code.

The class TrajectoryReader in io/trajectory.py has a method called __getitem__.

If I understand it correctly it will set the calculator to SinglePointCalculator upon reading
a trajectory file. Is my understanding correct? Does this mean we cannot save calculator
objects, other than SinglePointCalculator, together with atoms objects to a file?


    def __getitem__(self, i=-1):
        b = self.backend[i]
        if 'numbers' in b:
            # numbers and other header info was written alongside the image:
            atoms = read_atoms(b)
        else:
            # header info was not written because they are the same:
            atoms = read_atoms(b, header=[self.pbc, self.numbers, self.masses,
                                          self.constraints])
        if 'calculator' in b:
            results = {}
            implemented_properties = []
            c = b.calculator
            for prop in all_properties:
                if prop in c:
                    results[prop] = c.get(prop)
                    implemented_properties.append(prop)
            calc = SinglePointCalculator(atoms, **results)
            calc.name<http://calc.name/> = b.calculator.name<http://b.calculator.name/>
            calc.implemented_properties = implemented_properties

            if 'parameters' in c:
                calc.parameters.update(c.parameters)
            atoms.set_calculator(calc)

        return atoms



Met vriendelijke groeten,
Mit freundlichen Gr??en,
With kind regards,


Willem Offermans
Researcher Electrocatalysis SCT
VITO NV | Boeretang 200 | 2400 Mol
Phone:+32(0)14335263 Mobile:+32(0)492182073

Willem.Offermans at Vito.be<mailto:Willem.Offermans at Vito.be><mailto:Willem.Offermans at Vito.be<mailto:Willem.Offermans at Vito.be>>

[cid:982BA063-B96A-4A1B-89AB-5A01CA9FC70D at vito.local]

On 20 Jan 2020, at 16:17, Offermans Willem via ase-users <ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk><mailto:ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk>>> wrote:

Dear ASE friends,

If I save atoms objects to a file, the attached calculator object get lost.

I read a trajectory file with atoms objects. The calculators of each are
set to ``calculator=SinglePointCalculator(?)``. If I change this to
``calculator=SocketIOCalculator(?)`` and save the atoms objects to
a file, the calculator is reset upon next read.

Most probably, the info about the calculator is not saved and the settings of
``calculator=SinglePointCalculator(?)`` is initialised during read.
Is this correct?

Is it possible to save the calculator to a file as is done when saving the atoms
object to a database?
How can I save the calculator setting?




Met vriendelijke groeten,
Mit freundlichen Gr??en,
With kind regards,


Willem Offermans
Researcher Electrocatalysis SCT
VITO NV | Boeretang 200 | 2400 Mol
Phone:+32(0)14335263 Mobile:+32(0)492182073

Willem.Offermans at Vito.be<mailto:Willem.Offermans at Vito.be><mailto:Willem.Offermans at Vito.be<mailto:Willem.Offermans at Vito.be>>

<vito.jpg>

Indien u VITO Mol bezoekt, hou aub er dan rekening mee dat de hoofdingang voortaan enkel bereikbaar is vanuit de richting Dessel-Retie, niet vanuit richting Mol, zie vito.be/route<http://vito.be/route>.<http://www.vito.be/route>
If you plan to visit VITO at Mol, then please note that the main entrance can only be reached coming from Dessel-Retie and no longer coming from Mol, see vito.be/en/contact/locations<http://vito.be/en/contact/locations>.<http://www.vito.be/en/contact/locations>
VITO Disclaimer: http://www.vito.be/e-maildisclaimer
_______________________________________________
ase-users mailing list
ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk><mailto:ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk>>
https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20200121/61d6b333/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vito.jpg
Type: image/jpeg
Size: 15232 bytes
Desc: vito.jpg
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20200121/61d6b333/attachment.jpg>

------------------------------

_______________________________________________
ase-users mailing list
ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk>
https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users

End of ase-users Digest, Vol 139, Issue 16
******************************************
_______________________________________________
ase-users mailing list
ase-users at listserv.fysik.dtu.dk<mailto:ase-users at listserv.fysik.dtu.dk>
https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20200121/66e91387/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vito.jpg
Type: image/jpeg
Size: 15232 bytes
Desc: vito.jpg
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20200121/66e91387/attachment-0001.jpg>


More information about the ase-users mailing list