Skip to content

Commit 5b810d3

Browse files
committed
corrections
1 parent 8e74961 commit 5b810d3

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

dqc/api/properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _hessian_pos(qc: BaseQCCalc) -> torch.Tensor:
348348
atompos = system.atompos
349349

350350
# check if the atompos requires grad
351-
_check_differentiability(atompos, "atom positions", "hessian")
351+
_check_differentiability(atompos, "atom positions", "optimal geometry")
352352

353353
# calculate the jacobian
354354
jac_e_pos = _jac(ene, atompos, create_graph=True) # (natoms * ndim)
@@ -500,8 +500,8 @@ def _get_energy(atompos: torch.Tensor) -> torch.Tensor:
500500
return ene
501501

502502
# get the minimal enery position
503-
minpos = xitorch.optimize.minimize(_get_energy, atompos, method="gd", maxiter=200,
504-
step=1e-2)
503+
minpos = xitorch.optimize.minimize(_get_energy, atompos, method="gd", maxiter=200,
504+
step=1e-2)
505505

506506
return minpos
507507

dqc/system/mol.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import List, Union, Optional, Tuple, Dict
23
import warnings
34
import torch
@@ -294,7 +295,16 @@ def getparamnames(self, methodname: str, prefix: str = "") -> List[str]:
294295
else:
295296
raise KeyError("Unknown methodname: %s" % methodname)
296297

297-
def make_copy(self, **kwargs) -> "Mol":
298+
def make_copy(self, **kwargs) -> Mol:
299+
"""
300+
Returns a copy of the system identical to the orginal expect for new
301+
parameters set in the kwargs.
302+
303+
Arguments
304+
---------
305+
kwargs
306+
Must be the same kwargs as Mol.
307+
"""
298308
# create dictionary of all parameters
299309
parameters = {
300310
'moldesc': (self.atomzs, self.atompos),

dqc/system/sol.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import Optional, Tuple, Union, List, Dict
23
import torch
34
import numpy as np
@@ -242,7 +243,16 @@ def requires_grid(self) -> bool:
242243
def getparamnames(self, methodname: str, prefix: str = "") -> List[str]:
243244
pass
244245

245-
def make_copy(self, **kwargs) -> "Sol":
246+
def make_copy(self, **kwargs) -> Sol:
247+
"""
248+
Returns a copy of the system identical to the orginal expect for new
249+
parameters set in the kwargs.
250+
251+
Arguments
252+
---------
253+
kwargs
254+
Must be the same kwargs as Sol.
255+
"""
246256
# create dictionary of all parameters
247257
parameters = {
248258
'soldesc': (self.atomzs, self.atompos),

dqc/test/test_properties.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,23 @@ def test_optimal_geometry(h2o_qc):
449449

450450
# create a new h2o with poor initial geometry
451451
h2o_init = torch.tensor([
452-
[0.0, 0.0, 0.215],
452+
[0.0, 0.0, 0.214],
453453
[0.0, 1.475, -0.863],
454454
[0.0, -1.475, -0.863],
455455
], dtype=dtype).requires_grad_()
456456

457+
# use bond length to assess optimal geometry as they are rotation invariant
458+
def bond_length(h2o):
459+
# Get the bond lengths of an h20 molecule
460+
return torch.stack([(h2o[0] - h2o[1]).norm(), (h2o[0] - h2o[2]).norm()])
461+
457462
# check starting geometry is not optimal
458-
assert not torch.allclose(h2o_init, pyscf_h2o_opt, rtol=2e-4)
463+
assert not torch.allclose(bond_length(h2o_init), bond_length(pyscf_h2o_opt), rtol=2e-4)
459464

460465
# optimize geometry
461466
system = h2o_qc.get_system()
462467
new_system = system.make_copy(moldesc=(system.atomzs, system.atompos))
463468
new_qc = h2o_qc.__class__(new_system).run()
464469
h2o_opt = optimal_geometry(new_qc)
465470

466-
assert torch.allclose(h2o_opt, pyscf_h2o_opt, rtol=2e-4)
471+
assert torch.allclose(bond_length(h2o_opt), bond_length(pyscf_h2o_opt), rtol=2e-4)

0 commit comments

Comments
 (0)