Skip to content

Commit

Permalink
add the update dftb function
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed May 6, 2024
1 parent 10c3e88 commit 365ea7a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
author = "Qiang Zhu, Scott Fredericks, Kevin Parrish"

# The short X.Y version
version = "0.6.6"
version = "0.6.7"
# The full version, including alpha/beta/rc tags
release = "0.6.6"
release = "0.6.7"

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ab-initio generation of random crystal structures. It has the following features
- Structural manipulation via symmetry relation (both subgroup and supergroup)
- Geometry optimization from built-in and external optimization methods

The current version is ``0.6.6`` at `GitHub <https://github.com/qzhu2017/PyXtal>`_.
The current version is ``0.6.7`` at `GitHub <https://github.com/qzhu2017/PyXtal>`_.
It is available for use under the MIT license. Expect updates upon request by
`Qiang Zhu\'s group <https://qzhu2017.github.io>`_ at the
University of North Carolina at Charlotte.
Expand Down
70 changes: 70 additions & 0 deletions pyxtal/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,76 @@ def update_row_ff_energy(self, ff='reaxff', ids=(None, None),
ff_relaxed=xtal.to_file())


def update_row_dftb_energy(self, skf_dir, cmd, steps=500,
ids=(None, None),
calc_folder='tmp',
criteria=None,
overwrite=False):
"""
Update row ff_energy with GULP calculator
Args:
skf_dir (str): GULP force field library (e.g., 'reaxff', 'tersoff')
cmd (str): DFTB command
steps (int): relaxation steps
ids (tuple): row ids e.g., (0, 100)
calc_folder (str): temporary folder for GULP calculations
overwrite (bool): remove the existing attributes
"""
from pyxtal.interface.dftb import DFTB_relax

if not os.path.exists(calc_folder): os.makedirs(calc_folder)

(min_id, max_id) = ids
if min_id is None: min_id = 1
if max_id is None: max_id = self.db.count() + 10000

cwd = os.getcwd()
for row in self.db.select():
if overwrite or not hasattr(row, 'dftb_energy'):
if min_id <= row.id <= max_id:
if hasattr(row, 'similarity'):
sim0 = row.similarity
else:
sim0 = 0.0

xtal = self.get_pyxtal(row.id)
atoms = xtal.to_ase(resort=False)

os.environ['ASE_DFTB_COMMAND'] = cmd

# Actual geometry optimization
try:
s = DFTB_relax(atoms, skf_dir, True, steps, logfile='ase.log')
except:
s = None
print("Problem in DFTB Geometry optimization", row.id)
xtal.to_file('bug.cif')
os.chdir(cwd)

#s = DFTB_relax(atoms, skf_dir, True, steps, logfile='ase.log')

if s is not None:
c = pyxtal(); c.from_seed(s)
eng = s.get_potential_energy()/len(s)
stress = s.get_stress()/0.006241509125883258

if criteria is not None:
status = xtal.check_validity(criteria)
else:
status = True

header = "{:4d}".format(row.id)
dicts = {'validity': status, 'energy': eng}
print(xtal.get_xtal_string(header=header, dicts=dicts))
print(" Stress: {:7.2f}{:7.2f}{:7.2f}".format(*stress[:3]))

if status:
self.db.update(row.id,
dftb_energy=eng,
dftb_relaxed=xtal.to_file())


def update_row_topology(self, StructureType='Auto', overwrite=True):
"""
Update row topology base on the CrystalNets.jl
Expand Down
1 change: 1 addition & 0 deletions pyxtal/interface/dftb.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def make_Hamiltonian(skf_dir, atom_types, disp, kpts, write_band=False, use_omp=
'Analysis_WriteBandOut': 'No',
'Analysis_MullikenAnalysis': 'No',
'Analysis_CalculateForces': 'Yes',
'Analysis_PrintForces': 'Yes',
}
if write_band:
kwargs['Analysis_WriteBandOut'] = 'Yes'
Expand Down
2 changes: 1 addition & 1 deletion pyxtal/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.6"
__version__ = "0.6.7"

0 comments on commit 365ea7a

Please sign in to comment.