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

changed default basis, added ecp option #156

Merged
merged 6 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_frozen_core(molecule):

# Counting how many of each element is in the molecule.
elements = {i: molecule.elements.count(i) for i in molecule.elements}
frozen_core = sum([v * core_orbitals[k] for k, v in elements.items()])
frozen_core = sum([v * core_orbitals.get(k, 0) for k, v in elements.items()])

return frozen_core

Expand Down
20 changes: 14 additions & 6 deletions tangelo/toolboxes/molecular_computation/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Molecule:
n_min_orbitals: int = field(init=False)

def __post_init__(self):
mol = self.to_pyscf(basis="sto-3g", symmetry=False)
mol = self.to_pyscf()
self.n_atoms = mol.natm
self.n_electrons = mol.nelectron
self.n_min_orbitals = mol.nao_nr()
Expand All @@ -107,21 +107,26 @@ def elements(self):
def coords(self):
return np.array([self.xyz[i][1] for i in range(self.n_atoms)])

def to_pyscf(self, basis="sto-3g", symmetry=False):
def to_pyscf(self, basis="CRENBL", symmetry=False, ecp=None):
ValentinS4t1qbit marked this conversation as resolved.
Show resolved Hide resolved
"""Method to return a pyscf.gto.Mole object.

Args:
basis (string): Basis set.
symmetry (bool): Flag to turn symmetry on
ecp (dict): Dictionary with ecp definition for each atom e.g. {"Cu": "crenbl"}

Returns:
pyscf.gto.Mole: PySCF compatible object.
"""
if ecp is None:
JamesB-1qbit marked this conversation as resolved.
Show resolved Hide resolved
ecp = dict()

mol = gto.Mole(atom=self.xyz)
mol.basis = basis
mol.charge = self.q
mol.spin = self.spin
mol.symmetry = symmetry
mol.ecp = ecp
JamesB-1qbit marked this conversation as resolved.
Show resolved Hide resolved
mol.build()

self.xyz = list()
Expand All @@ -137,7 +142,7 @@ def to_file(self, filename, format=None):
filename (str): The name of the file to output the geometry.
format (str): The output type of "raw", "xyz", or "zmat". If None, will be inferred by the filename
"""
mol = self.to_pyscf(basis="sto-3g")
mol = self.to_pyscf()
mol.tofile(filename, format)

def to_openfermion(self, basis="sto-3g"):
Expand All @@ -161,6 +166,8 @@ class SecondQuantizedMolecule(Molecule):

Attributes:
basis (string): Basis set.
ecp (dict): The effective core potential (ecp) for any atoms in the molecule.
JamesB-1qbit marked this conversation as resolved.
Show resolved Hide resolved
e.g. {"C": "crenbl"} use CRENBL ecp for Carbon atoms.
symmetry (bool or str): Whether to use symmetry in RHF or ROHF calculation.
Can also specify point group using pyscf allowed string.
e.g. "Dooh", "D2h", "C2v", ...
Expand Down Expand Up @@ -195,6 +202,7 @@ class SecondQuantizedMolecule(Molecule):
actives_mos (list): Active MOs indexes.
"""
basis: str = "sto-3g"
ecp: dict = field(default_factory=dict)
symmetry: bool = False
frozen_orbitals: list or int = field(default="frozen_core", repr=False)

Expand Down Expand Up @@ -273,7 +281,7 @@ def _compute_mean_field(self):
(mf_energy, mo_energies, mo_occ, n_mos and n_sos).
"""

molecule = self.to_pyscf(self.basis, self.symmetry)
molecule = self.to_pyscf(self.basis, self.symmetry, self.ecp)

self.mean_field = scf.RHF(molecule)
self.mean_field.verbose = 0
Expand Down Expand Up @@ -331,7 +339,7 @@ def _convert_frozen_orbitals(self, frozen_orbitals):
virtual and frozen virtual orbital indexes.
"""

if frozen_orbitals == "frozen_core":
if frozen_orbitals == "frozen_core" and not self.ecp:
frozen_orbitals = get_frozen_core(self.to_pyscf(self.basis))
elif frozen_orbitals is None:
frozen_orbitals = 0
Expand Down Expand Up @@ -456,7 +464,7 @@ def get_integrals(self, mo_coeff=None, consider_frozen=True):
"""

# Pyscf molecule to get integrals.
pyscf_mol = self.to_pyscf(self.basis, self.symmetry)
pyscf_mol = self.to_pyscf(self.basis, self.symmetry, self.ecp)
if mo_coeff is None:
mo_coeff = self.mean_field.mo_coeff

Expand Down