aiidalab / aiidalab-widgets-base

Reusable widgets for AiiDAlab applications
MIT License
7 stars 17 forks source link

Add XTB optimizer structure editor #161

Open cpignedoli opened 3 years ago

cpignedoli commented 3 years ago

It could be very useful, for example when generating molecules from smiles, to add the posisbility of optimizing a structure with xtb this can be done as follows:

(see https://github.com/pgasparo/smiles2ase also for one example)

suppose mol is an ase structure:

from xtb.ase.calculator import XTB
mol.pbc=False #needed
mol.calc=XTB(method="GFNFF")
## example on how to fux atoms below:
from ase.constraints import FixAtoms

fix_z=max(mol[np.where(np.asarray(mol.get_chemical_symbols())=="Au")[0]].positions[:,2])
idatoms_tobefixed = np.where(mol.positions[:,2]<fix_z)[0]
atoms_tobefixed = FixAtoms(idatoms_tobefixed)
mol.set_constraint(atoms_tobefixed)

from ase.optimize.lbfgs import LBFGS

hareV=27.211399

# Remove logfile=none to see an output of the minimization process
opt = LBFGS(mol,logfile=None)
opt.run(fmax=0.0001)
forces = mol.get_forces()
energy = mol.get_potential_energy()

#
print("Final energy is", energy, "eV")
print("Final energy is", energy/hareV, "hartree")

#print("All done, final positions are:")
#print(positions)
danielhollas commented 2 years ago

I am actually working on this right now: Generate structure from SMILES using SmilesWidget with RDKit, optimize with XTB. One challenge will be to make this performant. It would be good to know whether there is interest to have this functionality on master.

yakutovicha commented 2 years ago

Generate structure from SMILES using SmilesWidget with RDKit, optimize with XTB.

Thanks, @danielhollas, that is definitely a good thing to have. May I suggest implementing it as a structure editor that can be injected into the StructureManagerWidget? https://github.com/aiidalab/aiidalab-widgets-base/blob/4badc55394fb6e8f49eb0388b09ff9a7473952b0/aiidalab_widgets_base/structures.py#L42

The point is: independently of where the structure is coming from, one might still want to modify it.

For the example on how a structure editor can be used see here: https://github.com/aiidalab/aiidalab-widgets-base/blob/master/notebooks/structures.ipynb

danielhollas commented 2 years ago

Interesting idea, I'll look into it, thanks!