[ase-users] Save SocketIOCalculator property to file

Maxime Van den Bossche maxime.cp.vandenbossche at gmail.com
Tue Jan 21 13:35:57 CET 2020


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 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 = 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>
>
> [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>>
> 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>
>
> <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://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://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>
> 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
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>
> End of ase-users Digest, Vol 139, Issue 16
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20200121/403b108a/attachment-0001.html>


More information about the ase-users mailing list