QuantumMisaka / ATST-Tools

Advanced ASE Transition State Tools for ABACUS
14 stars 6 forks source link

ASE Error: "Atoms object has no calculator." #12

Closed MoseyQAQ closed 5 months ago

MoseyQAQ commented 5 months ago

Dear Developer, thanks for your contribution.

I want to search for the transition state of the diffusion of an oxygen atom in the Perovskite oxide with ABACUS + ATST-Tools.

I have optimized the structures of the initial and final state using ABACUS. Then I use pymatgen-analysis-diffusion package to build an init_neb_chain.traj (Which can automatically match the atoms between initial and final states, and handle the PBC). After submitting the task, I encountered an error: raise RuntimeError('Atoms object has no calculator.').

Here is my calculation setting: n_iamges = 8 node = 4 ntasks-per-node=2 cpus-per-task=32

The input file and log file are in the attachment. Thank you! input_log.zip

QuantumMisaka commented 5 months ago

@MoseyQAQ Thanks for your usage and issue!

The problem may be in parallel running process, can you try to avoid mpirun and just run python neb_run.py to do serial NEB (just a try) to see if the problem still exist ? Also you can try to submit the parallel job twice as a try

if parallel run still have problem, I will remove the if parser in line 86-95 of abacus_neb.py

        # set calculator
        images = self.init_chain
        for num, image in enumerate(images[1:-1]):
            # only set calc for inter-image
            # we can only use one rank for one inter-image
            if self.parallel:
                if world.rank == num % world.size:
                    image.calc = self.set_calculator()
            # else:
            image.calc = self.set_calculator()

It is recommended to try that

Also, it is very welcomed to contribute your code for using pymatgen-analysis-diffusion package to build init_neb_chain, you can give a PR, thanks!

MoseyQAQ commented 5 months ago

Thanks for your reply!

I will carefully check all your suggestions and give my feedback as soon as possible.

MoseyQAQ commented 5 months ago

I have done the serial NEB and tried to resubmit the parallel job twice, The same error is still here.

However after I checked the source code of ASE's NEB module, I found the reason for this error message:

  1. In the standard workflow, we use ABACUS for structural optimization of the initial and final states, then use ASE to read ABACUS's output files (namely running_relax.log). Following that, we interpolate based on the initial and final states to generate the trajectory file for NEB. At this point, both the initial and final states have a SinglePointCalculator.

  2. I directly read the optimized structure files instead of running_relax.log, which resulted in my initial and final states lacking a SinglePointCalculator.

  3. In your code (also the official ASE examples), calculators are only set for the intermediate states, without consideration for the initial and final states. This is because, in these examples, the initial and final states already come with a SinglePointCalculator.

  4. For NEB calculations in ASE, it is necessary to evaluate the energies of the initial and final states (see ase/mep/neb.py, lines 442-444).

How to fix this:

from ase.io import read,write 
from ase.calculators.singlepoint import SinglePointCalculator
traj = read('out.traj',index=':')

# We can manually set the SinglePointCalculator
traj[0].calc = SinglePointCalculator(traj[0],energy=-228012.4851218159)
traj[-1].calc = SinglePointCalculator(traj[-1],energy=-228011.8825616564)

write('neb.traj',traj)

After doing these steps, it seems that the code now can run normally.

QuantumMisaka commented 5 months ago

Excellent @MoseyQAQ

I've forgotten it and I spent a lot of time to deal with this when I reconstruct the code. in NEB of ASE, the IS and FS must have energy. (in VASP it is the same ?). so if your init_neb_chain.traj do not have energy in IS and FS, there will be error neither no calculator nor no energy.

I consider you can do some modification of your neb_make script based on pymatgen to avoid the redundant SCF calculation of IS and FS

MoseyQAQ commented 5 months ago

@QuantumMisaka Thanks for your suggestions! In VASP, you don't need to do the same thing. I will also try to contribute my code about using pymatgen to build init_neb_chain to this repo (it will be my first PR, xD)

QuantumMisaka commented 5 months ago

@MoseyQAQ My recommendation is that you can submit a PR to contribute your pymatgen + ase independent script which do neb_make function by pymatgen method, which will be parallel to the neb_make.py in ATST-Tools now.

Thanks a lot !