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

Initial work on separating AVAS from ASET #441

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions forte/modules/objects_factory_psi4.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from forte.data import ForteData

from forte.proc.orbital_helpers import add_orthogonal_vectors, orbital_projection, dmrg_initial_orbitals
from forte.proc.orbital_helpers import add_orthogonal_vectors, make_avas_orbitals, dmrg_initial_orbitals
from forte.proc.external_active_space_solver import write_wavefunction, read_wavefunction

from .module import Module
Expand Down Expand Up @@ -358,7 +358,10 @@ def prepare_forte_objects_from_wavefunction(self, data, temp_mo_space_info):
The MO space information object
"""
# Call methods that project the orbitals (AVAS, embedding)
data.mo_space_info = orbital_projection(data.psi_wfn, data.options, temp_mo_space_info)
if data.options.get_bool("AVAS"):
make_avas_orbitals(data)

data.mo_space_info = temp_mo_space_info # TODO this should be removed

# Reorder active orbitals for DMRG after AVAS
if data.options.get_str("ACTIVE_SPACE_SOLVER") in ["DMRG", "BLOCK2"]:
Expand Down
43 changes: 20 additions & 23 deletions forte/proc/orbital_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,33 @@ def dump_orbitals(wfn, filename="forte_Ca.npz"):
psi4.core.print_out(" Done\n")


def orbital_projection(ref_wfn, options, mo_space_info):
def make_avas_orbitals(data):
"""
Functions that pre-rotate orbitals before calculations;
Requires a set of reference orbitals and mo_space_info.

AVAS: an automatic active space selection and projection;
Embedding: simple frozen-orbital embedding with the overlap projector.

Return a Forte MOSpaceInfo object
Makes atomic valence active space (AVAS) orbitals.
Used to automate active space selection. It requires a set of reference orbitals
"""
if options.get_bool("AVAS"):
# Find the subspace projector
# - Parse the subspace planes for pi orbitals
from .aosubspace import parse_subspace_pi_planes
# Find the subspace projector
# - Parse the subspace planes for pi orbitals
from .aosubspace import parse_subspace_pi_planes

pi_planes = parse_subspace_pi_planes(data.psi_wfn.molecule(), data.options.get_list("SUBSPACE_PI_PLANES"))

pi_planes = parse_subspace_pi_planes(ref_wfn.molecule(), options.get_list("SUBSPACE_PI_PLANES"))
# - Create the AO subspace projector
ps = forte.make_aosubspace_projector(data.psi_wfn, data.options, pi_planes)

# - Create the AO subspace projector
ps = forte.make_aosubspace_projector(ref_wfn, options, pi_planes)
# Apply the projector to rotate orbitals
forte.make_avas(data.psi_wfn, data.options, ps)

# Apply the projector to rotate orbitals
forte.make_avas(ref_wfn, options, ps)

def make_embedding_orbitals(data):
"""
Implements a simple frozen-orbital embedding with the overlap projector (ASET(mf)).
Return a Forte MOSpaceInfo object
"""
# Create the fragment(embedding) projector and apply to rotate orbitals
if options.get_bool("EMBEDDING"):
forte.print_method_banner(["Frozen-orbital Embedding", "Nan He"])
fragment_projector, fragment_nbf = forte.make_fragment_projector(ref_wfn)
return forte.make_embedding(ref_wfn, options, fragment_projector, fragment_nbf, mo_space_info)
else:
return mo_space_info
forte.print_method_banner(["Frozen-orbital Embedding", "Nan He"])
fragment_projector, fragment_nbf = forte.make_fragment_projector(data.psi_wfn)
return forte.make_embedding(data.psi_wfn, data.options, fragment_projector, fragment_nbf, data.mo_space_info)


def dmrg_initial_orbitals(wfn, options, mo_space_info):
Expand Down
8 changes: 6 additions & 2 deletions forte/pymodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
make_hamiltonian,
)
from forte.proc.dsrg import ProcedureDSRG
from forte.proc.orbital_helpers import dump_orbitals
from forte.proc.orbital_helpers import dump_orbitals, make_embedding_orbitals


def forte_driver(data: ForteData):
Expand Down Expand Up @@ -172,7 +172,7 @@ def energy_forte(name, **kwargs):
elif data.options.get_str("INT_TYPE") == "PYSCF":
data = ObjectsFromPySCF(kwargs.get("pyscf_obj"), options=kwargs).run(data)
else:
data = ObjectsFromPsi4(**kwargs).run(data)
data = ObjectsFromPsi4(**kwargs).run(data) # <--- This is where AVAS runs

start = time.time()

Expand Down Expand Up @@ -204,6 +204,10 @@ def energy_forte(name, **kwargs):
data = MCSCF(active_space_solver_type).run(data)
energy = data.results.value("mcscf energy")

if data.options.get_bool("EMBEDDING"):
data.mo_space_info = make_embedding_orbitals(data)
data.ints = forte.make_ints_from_psi4(data.psi_wfn, data.options, data.scf_info, data.mo_space_info)

# Run a method
if job_type == "NONE":
psi4.core.set_scalar_variable("CURRENT ENERGY", energy)
Expand Down
Loading