qcscine / sparrow

https://scine.ethz.ch
BSD 3-Clause "New" or "Revised" License
78 stars 15 forks source link

How I can run geometry optimization? #21

Closed ProkopHapala closed 11 months ago

ProkopHapala commented 1 year ago

I was reading the manual and I cannot see anything about geometry relaxation. I see only option gradient --gradient

But I see submodule lbfgspp is compiled during installation, therefore I guess there should be some geometry optimization inside?

steinmig commented 1 year ago

The lbfgspp submodule is a submodule of scine_utilities, which also includes our own optimizers.

Sparrow only provides properties for the optimization such as the energy and gradients.

You can optimize a structure in python with a python binding of scine_utilities:

import scine_utilities as su
import scine_sparrow

# prepare structure
elements = [su.ElementType.H, su.ElementType.H]
positions = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]]
atoms = su.AtomCollection(elements, positions)
# prepare calculator
calc = su.core.get_calculator("pm6")
calc.structure = atoms
log = su.core.Log()
log.output.remove("cout")
calc.log = log 
calc.set_required_properties([su.Property.Gradients, su.Property.Energy])
# optimize
opt_log = su.core.Log()
optimized_atoms = su.geometry_optimize(calc, opt_log, su.Optimizer.Bfgs)
su.io.write("optimized.xyz", optimized_atoms)

However, modifying some bits here requires some deeper knowledge of the code structure. For easy usability, I'd recommend Scine ReaDuct, which handles all these underlying structures for you. It also has a manual and can be used by the command line and via Python bindings