Skip to content

[Code scan] Psi4 input writer ignores the requested method #992

Description

@njzjz

This issue is part of a Codex global repository code scan.

The Psi4 input writer accepts a method argument, but the generated template hard-codes WB97M-D3BJ in the gradient(...) call. Passing any other method still writes gradient("WB97M-D3BJ", ...).

Affected code:
https://github.com/deepmodeling/dpdata/blob/a7a50bfc096e1a65470af6f1c48152dc0275ec1c/dpdata/formats/psi4/input.py#L150-L173

The current test only verifies the default method, so this is not caught:

class TestPsi4Input(unittest.TestCase):
def test_psi4_input(self):
system = dpdata.LabeledSystem("psi4/psi4.out", fmt="psi4/out")
with tempfile.NamedTemporaryFile("r") as f:
system.to_psi4_inp(f.name, method="WB97M-D3BJ", basis="def2-TZVPPD")
content = f.read()
self.assertEqual(
content,
textwrap.dedent(
"""\
molecule {
C 0.692724290 -0.280972290 0.149966626
C -0.690715864 0.280527594 -0.157432416
H 1.241584247 -0.707702380 -0.706342645
H 0.492994289 -1.086482665 0.876517411
H 1.330104482 0.478557878 0.633157279
H -1.459385451 -0.498843014 -0.292862623
H -0.623545813 0.873377524 -1.085142510
H -1.005665735 0.946387574 0.663566976
0 1
}
set basis def2-TZVPPD
set gradient_write on
G, wfn = gradient("WB97M-D3BJ", return_wfn=True)
wfn.energy()
wfn.gradient().print_out()
"""
),

Minimal reproducer:

import dpdata

system = dpdata.LabeledSystem("tests/psi4/psi4.out", fmt="psi4/out")
system.to_psi4_inp("tmp.inp", method="hf", basis="sto-3g")
print(open("tmp.inp").read())

Current generated input still contains:

G, wfn = gradient("WB97M-D3BJ", return_wfn=True)

Expected generated input should use the requested method:

G, wfn = gradient("hf", return_wfn=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions