Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using external potential in python broken in case of Angstrom units #3147

Open
timostrunk opened this issue Mar 21, 2024 · 0 comments · May be fixed by #3148
Open

Using external potential in python broken in case of Angstrom units #3147

timostrunk opened this issue Mar 21, 2024 · 0 comments · May be fixed by #3148

Comments

@timostrunk
Copy link
Contributor

When using angstrom units, when parsing the molecule and including an external_potential, the geometry of the molecule gets scaled twice leading to incorrect energies. This only happens, when using python and not psithon.
This can easily be seen when adding a 0 charge far away of the molecule to the simulation, which changes energies significantly.

I already prepared a PR to fix this, this is just for reference.

To reproduce the problem, use the following:

#! Python equivalent of extern5 test:
#! External potential sanity check with 0 charge far away
#! Checks if all units behave the same and energy is same as no
#! potential
import numpy as np
import psi4.core
import psi4

b2a=0.529177249
# Coordinates added in angstrom
coords = np.array([[ -0.778803000000 , 0.000000000000,  1.132683000000],
 [ -0.666682000000,  0.764099000000,  1.706291000000],
 [ -0.666682000000,  -0.764099000000 , 1.706290000000]])
elements = ["O","H","H"]
molecule_ang  = psi4.core.Molecule.from_arrays(geom=coords,     elem=elements, fix_symmetry="c1", fix_com=True, fix_orientation=True)
molecule_bohr = psi4.core.Molecule.from_arrays(geom=coords/b2a, elem=elements, fix_symmetry="c1", fix_com=True, fix_orientation=True, units="Bohr")

external_potentials = [[0.00, np.array([10.0,10.0,10.0]) / b2a]]

psi4.set_options( {
    "scf_type": "df",
    "d_convergence": 12,
    "basis": "STO-3G",
    "print": 0,
    "debug": 0,
})


ene_bohr_charges = psi4.energy('scf', molecule=molecule_bohr, external_potentials=external_potentials)
ene_bohr_pure = psi4.energy('scf', molecule=molecule_bohr)
psi4.compare_values(ene_bohr_charges, ene_bohr_pure, 6, "Bohr geometry, charges vs no charges energy equality")

ene_ang_pure = psi4.energy('scf', molecule=molecule_ang)
psi4.compare_values(ene_ang_pure, ene_bohr_pure, 6, "No charges, Bohr vs Angstrom geometry energy equality")

ene_ang_charges = psi4.energy('scf', molecule=molecule_ang, external_potentials=external_potentials)
psi4.compare_values(ene_ang_charges, ene_ang_pure, 6, "Angstrom geometry, charges vs no charges energy equality")

The last line should fail with the current psi4.

timostrunk added a commit to timostrunk/psi4 that referenced this issue Mar 21, 2024
@timostrunk timostrunk linked a pull request Mar 21, 2024 that will close this issue
7 tasks
timostrunk added a commit to timostrunk/psi4 that referenced this issue Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant