Skip to content

Commit

Permalink
BugFix: Geometry Optimizer changed to Rational (#23)
Browse files Browse the repository at this point in the history
Geometry optimizer was changed to Rational due to convergence issues.
  • Loading branch information
galjos authored Aug 1, 2024
2 parents b2eae82 + 5477c80 commit b21764a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
5 changes: 3 additions & 2 deletions ThermoScreening/calculator/dftbplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Geoopt(Dftb):
"""
Custom DFTB+ calculator to optimize the system with LBFGS solver.
Custom DFTB+ calculator to optimize the system with the 'GeometryOptimisation' driver (Rational).
It is a subclass of ase.calculators.dftb.Dftb. It uses the
'LBFGS' driver.
Expand Down Expand Up @@ -72,7 +72,8 @@ def __init__(
label=label,
slako_dir=BASE_PATH + "../external/slakos/3ob-3-1/",
Hamiltonian_Charge=charge,
Driver_="LBFGS",
Driver_="GeometryOptimisation",
Driver_Optimiser="Rational {}",
Driver_MaxForceComponent=max_force,
Driver_OutputPrefix="geo_opt",
**kwargs,
Expand Down
8 changes: 6 additions & 2 deletions examples/Notebooks/dftbplus/ThermoScreening.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
"outputs": [],
"source": [
"dftb_parameters = dict(\n",
"\n",
" # Driver\n",
" # Driver_MaxSteps=1000,\n",
" \n",
" # SCC\n",
" Hamiltonian_SCC=\"Yes\",\n",
" Hamiltonian_MaxSCCIterations=250,\n",
Expand Down Expand Up @@ -117,7 +121,7 @@
"\n",
" # Analysis\n",
" Analysis_=\"\",\n",
" Analysis_CalculateForces=\"Yes\",\n",
" Analysis_PrintForces=\"Yes\",\n",
" Analysis_MullikenAnalysis=\"Yes\",\n",
"\n",
" # ParserVersion\n",
Expand Down Expand Up @@ -235,7 +239,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
]

dependencies = [
"numpy",
"numpy < 2.0",
"argparse",
"scipy",
"pymatgen",
Expand Down
32 changes: 18 additions & 14 deletions tests/calculator/test_dftbplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class TestDftbplus:

# Test the DFTB+ calculator
def test_dftb(self):
assert os.system("which dftb+ > /dev/null") == 0, "DFTB+ is not installed."
assert os.system("which modes > /dev/null") == 0, "Modes is not installed."
assert os.system(
"which dftb+ > /dev/null") == 0, "DFTB+ is not installed."
assert os.system(
"which modes > /dev/null") == 0, "Modes is not installed."

# Test the Geoopt class
@pytest.mark.parametrize("example_dir", ["calculator"])
Expand Down Expand Up @@ -57,9 +59,12 @@ def test_hessian(self, test_with_data_dir):

# create an instance of the Hessian class
optimizer = Geoopt(atoms, charge=0, **dftb_3ob_parameters)
hessian = Hessian(
optimizer.read(), charge=0, **dftb_3ob_parameters, delta=0.0005
)
atoms = optimizer.read()
print(atoms.get_positions())
hessian = Hessian(optimizer.read(),
charge=0,
**dftb_3ob_parameters,
delta=0.0005)

assert hessian.atoms == optimizer.read()
assert hessian.label == "second_derivative"
Expand All @@ -79,9 +84,10 @@ def test_modes(self, test_with_data_dir):

# create an instance of the Modes class
optimizer = Geoopt(atoms, charge=0, **dftb_3ob_parameters)
hessian = Hessian(
optimizer.read(), charge=0, **dftb_3ob_parameters, delta=0.0005
)
hessian = Hessian(optimizer.read(),
charge=0,
**dftb_3ob_parameters,
delta=0.0005)

assert os.path.exists("hessian.out")
assert os.path.exists("geo_opt.gen")
Expand All @@ -99,16 +105,14 @@ def test_modes(self, test_with_data_dir):

assert np.allclose(
wave_numbers[6:],
[
1.46185721e03,
3.60476561e03,
3.87736051e03,
],
[1462.29964226, 3604.10862879, 3876.6277397],
atol=1e-5,
)

@pytest.mark.parametrize("example_dir", ["calculator"])
def test_dftbplus_thermo(self, test_with_data_dir):
atoms = ase_io.read("water.xyz")
thermo = dftbplus_thermo(atoms, **dftb_3ob_parameters, delta=0.0005)
assert np.allclose(thermo.total_EeGtot(),-4.063049633277606 , atol=1e-5) # old value -4.064982703661
assert np.allclose(thermo.total_EeGtot(),
-4.0595598803365744,
atol=1e-5)
6 changes: 3 additions & 3 deletions tests/data/calculator/water.xyz
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
3
Properties=species:S:1:pos:R:3 pbc="F F F"
O -0.00566600 0.40130200 -0.00000000
H 0.79261600 -0.19855100 0.00000000
H -0.78695000 -0.20275100 -0.00000000
O -0.00566600 0.40130200 -1.00000000
H 0.79261600 -0.19855100 -1.00000000
H -0.78695000 -0.20275100 -1.00000000

0 comments on commit b21764a

Please sign in to comment.