Skip to content

Commit

Permalink
update ase dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Aug 12, 2024
1 parent 9603b96 commit 7f07a19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
47 changes: 24 additions & 23 deletions pyxtal/interface/ani.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import numpy as np
import torchani
from ase.constraints import ExpCellFilter
from ase.constraints import UnitCellFilter, FixSymmetry
from ase.optimize.fire import FIRE
from ase.spacegroup.symmetrize import FixSymmetry
#from ase.spacegroup.symmetrize import FixSymmetry


def ANI_relax(struc, opt_cell=False, step=500, fmax=0.1, logfile=None, max_time=6.0):
Expand All @@ -20,7 +20,7 @@ def ANI_relax(struc, opt_cell=False, step=500, fmax=0.1, logfile=None, max_time=
struc.set_calculator(calc)
struc.set_constraint(FixSymmetry(struc))
if opt_cell:
ecf = ExpCellFilter(struc)
ecf = UnitCellFilter(struc)
dyn = FIRE(ecf, a=0.1, logfile=logfile) if logfile is not None else FIRE(ecf, a=0.1)
else:
dyn = FIRE(struc, a=0.1, logfile=logfile) if logfile is not None else FIRE(struc, a=0.1)
Expand Down Expand Up @@ -55,26 +55,28 @@ def __init__(self, struc, opt_lat=True, logfile=None):
self.optimized = True
self.positions = None
self.cell = None
self.group = self.structure.group
self.cputime = 0
self.calculator = torchani.models.ANI2x().ase()
self.logfile = logfile

def run(self):
def run(self, steps=10):
t0 = time()
s = self.structure.to_ase(resort=False)
s.set_constraint(FixSymmetry(s))
s.set_calculator(self.calculator)
dyn = FIRE(s, a=0.1, logfile=self.logfile)
dyn.run(fmax=0.1, steps=10)
# print(s)
if self.opt_lat:
ecf = ExpCellFilter(s)
dyn = FIRE(ecf, a=0.1, logfile=self.logfile)
dyn.run(fmax=0.1, steps=10)
s.set_calculator(torchani.models.ANI2x().ase())#; print("Setup Fire")

if not self.opt_lat:
dyn = FIRE(s, a=0.1, logfile=self.logfile)#, force_consistent=False)
dyn.run(fmax=0.1, steps=steps)
else:
#ecf = FrechetCellFilter(s)
ecf = UnitCellFilter(s)
dyn = FIRE(ecf, a=0.1, logfile=self.logfile)#, force_consistent=False)
dyn.run(fmax=0.1, steps=steps)
self.structure.lattice.set_matrix(s.get_cell())

positions = s.get_scaled_positions()
try:
#try:
if True:
# s.write('../1.cif', format='cif')
count = 0
for _i, site in enumerate(self.structure.mol_sites):
Expand All @@ -89,21 +91,20 @@ def run(self):
coords1[j] = coords0[j] + diff
else:
print(coords1[j], coords1[j], np.linalg.norm(abs_diff))
import sys

sys.exit()
import sys; sys.exit()

site.update(coords1, self.structure.lattice)
count += len(site.molecule.mol) * site.wp.multiplicity
self.structure.optimize_lattice()
self.structure.energy = s.get_potential_energy()
self.cell = s.get_cell()
# print(self.structure.lattice)
except:
self.structure.energy = 10000
self.optimized = False
print("Structure is wrong after optimization")

#except:
# self.structure.energy = 10000
# self.optimized = False
# print("Structure is wrong after optimization")
s.set_calculator()
s.set_constraint()
self.cputime = time() - t0


Expand Down
5 changes: 2 additions & 3 deletions pyxtal/interface/dftb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
kpts2ndarray,
kpts2sizeandoffsets,
)
from ase.constraints import ExpCellFilter
from ase.constraints import UnitCellFilter, FixSymmetry
from ase.io import read
from ase.optimize.fire import FIRE
from ase.spacegroup.symmetrize import FixSymmetry
from ase.units import Bohr, Hartree

from pyxtal.util import Kgrid
Expand Down Expand Up @@ -220,7 +219,7 @@ def DFTB_relax(

# impose cell constraints
if opt_cell:
ecf = ExpCellFilter(struc, mask=mask)
ecf = UnitCellFilter(struc, mask=mask)
dyn = FIRE(ecf, logfile=logfile)
else:
dyn = FIRE(struc, logfile=logfile)
Expand Down
5 changes: 2 additions & 3 deletions pyxtal/interface/lammpslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import ase.units
import numpy as np
from ase.calculators.calculator import Calculator
from ase.constraints import ExpCellFilter
from ase.constraints import UnitCellFilter, FixSymmetry
from ase.optimize import LBFGS
from ase.optimize.fire import FIRE
from ase.spacegroup.symmetrize import FixSymmetry
from lammps import lammps


Expand Down Expand Up @@ -65,7 +64,7 @@ def opt_lammpslib(
struc.set_calculator(lammps)
struc.set_constraint(FixSymmetry(struc))
if opt_cell:
ecf = ExpCellFilter(struc, mask)
ecf = UnitCellFilter(struc, mask)
dyn = FIRE(ecf, logfile=logfile, a=a) if method == "FIRE" else LBFGS(ecf, logfile=logfile)
else:
dyn = FIRE(struc, logfile=logfile) if method == "FIRE" else LBFGS(struc, logfile=logfile)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"pymatgen>=2024.3.1",
"pandas>=2.0.2",
"networkx>=2.3",
"ase>=3.18.0", # covered by pymatgen
"ase>=3.23.0",
"scipy>=1.7.3",
"numpy>=1.26,<2", # prevent the use of numpy2
"importlib_metadata>=1.4",
Expand Down

0 comments on commit 7f07a19

Please sign in to comment.