def fcn(bparams, bpacker): # returns the same structure as basis above, but the parameters (alphas # and coeffs) are changed according to values in bparams basis = bpacker.construct_from_tensor(bparams) m = dqc.Mol("H 1 0 0; H -1 0 0", basis=basis) qc = dqc.HF(m).run() ene = qc.energy() return ene
def get_ene(atompos: torch.Tensor) -> torch.Tensor: atomzs = ["H", "H"] # H2 mol = dqc.Mol((atomzs, atompos), basis="3-21G") qc = dqc.HF(mol).run() ene = qc.energy() # calculate the energy return ene
def fcn(atompos, dev): atomzs = torch.cat((7. + dev, 7. - dev), dim=0) m = dqc.Mol((atomzs, atompos), basis="3-21G", spin=0) ene = dqc.HF(m).run().energy() return ene
C 3.4161 0.4295 -0.1982; C 2.5579 -2.1696 0.2094; H -0.9740 0.8710 3.4930; H -3.6211 2.8520 -0.0816; H -4.7222 -2.7845 0.8222; H -5.6716 -0.2763 2.8684; H -2.0785 -1.6104 -2.6430; H 0.0074 5.0941 1.2812; H -8.6971 -1.4445 0.0486; H 6.6186 -0.4860 -1.4846""" c4h5n_s = """N 0.0000 0.0000 2.1199; H 0.0000 0.0000 4.0021; C 0.0000 2.1182 0.6314; C 0.0000 -2.1182 0.6314; C 0.0000 1.3372 -1.8608; C 0.0000 -1.3372 -1.8608; H 0.0000 3.9843 1.4388; H 0.0000 -3.9843 1.4388; H 0.0000 2.5636 -3.4826; H 0.0000 -2.5636 -3.4826""" import time t0 = time.time() for i in range(1): moldesc = """N 0.0000 0.0000 2.1199; H 0.0000 0.0000 4.0021; C 0.0000 2.1182 0.6314; C 0.0000 -2.1182 0.6314; C 0.0000 1.3372 -1.8608; C 0.0000 -1.3372 -1.8608; H 0.0000 3.9843 1.4388; H 0.0000 -3.9843 1.4388; H 0.0000 2.5636 -3.4826; H 0.0000 -2.5636 -3.4826""" m = dqc.Mol(vitc_s, basis="cc-pvdz").densityfit() # m = dqc.Mol(c4h5n_s, basis="cc-pvdz").densityfit() ene = dqc.KS(m, xc="lda_x+lda_c_pw").run().energy() print(ene) t1 = time.time() print(t1 - t0)
import torch import dqc atomzs, atomposs = dqc.parse_moldesc("H 1 0 0; H -1 0 0") atomposs.requires_grad_() mol = dqc.Mol((atomzs, atomposs), basis="3-21G") qc = dqc.HF(mol).run() ene = qc.energy() force = -torch.autograd.grad(ene, atomposs)[0]