Skip to content

Commit

Permalink
Merge pull request #20 from adc-connect/uhf_support
Browse files Browse the repository at this point in the history
[WIP] UHF support for PySCF and Psi4
  • Loading branch information
maxscheurer authored Nov 11, 2019
2 parents b39789e + 6712022 commit ea25250
Show file tree
Hide file tree
Showing 35 changed files with 700 additions and 468 deletions.
7 changes: 5 additions & 2 deletions adcc/ExcitedStates.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def optimise_formatting(self, vectors):

@property
def linewidth(self):
"""The width of an amplitude line if a tensor is formatted with this class"""
"""
The width of an amplitude line if a tensor is formatted with this class
"""
# TODO This assumes a PP ADC matrix
if self.matrix.blocks == ["s"]:
nblk = 2
Expand Down Expand Up @@ -379,7 +381,8 @@ def describe(self, oscillator_strengths=True, state_dipole_moments=False,
Show the norms of the (1p1h, 2p2h, ...) blocks of the excited states,
by default ``True``.
"""
# TODO This function is quite horrible and definitely needs some refactoring
# TODO This function is quite horrible and definitely needs some
# refactoring

eV = constants.value("Hartree energy in eV")
has_dipole = "electric_dipole" in self.operators.available
Expand Down
24 changes: 13 additions & 11 deletions adcc/FormatDominantElements.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,41 @@ def __init__(self, mospaces, tolerance=0.01, index_format=FormatIndexAdcc):

def optimise_formatting(self, spaces_tensor_pairs):
"""
Optimise the formatting parameters of this class and the index_format class
in order to be able to nicely produce equivalently formatted tensor format
strings for all the passed spaces-tensor pairs.
Optimise the formatting parameters of this class and the index_format
class in order to be able to nicely produce equivalently formatted tensor
format strings for all the passed spaces-tensor pairs.
This function can be called multiple times.
"""
if not isinstance(spaces_tensor_pairs, list):
return self.optimise_formatting([spaces_tensor_pairs])

for spaces, tensor in spaces_tensor_pairs:
if not isinstance(spaces, (tuple, list)) or not isinstance(tensor, Tensor):
if not isinstance(spaces, (tuple, list)) or \
not isinstance(tensor, Tensor):
raise TypeError("spaces_tensor_pairs should be a list of "
"(spaces tuples, Tensor) tuples")
for indices, _ in _tensor_select_below_absmax(tensor, self.tolerance):
self.index_format.optimise_formatting([(spaces[j], idx)
for j, idx in enumerate(indices)])
self.index_format.optimise_formatting(
[(spaces[j], idx) for j, idx in enumerate(indices)])

def format_as_list(self, spaces, tensor):
"""Raw-format the dominant tensor elements as a list of tuples with one
tuple for each element. Each tuple has three entries, the formatted indices,
the formatted spins and the value"""
tuple for each element. Each tuple has three entries, the formatted
indices, the formatted spins and the value"""
ret = []
for indices, value in _tensor_select_below_absmax(tensor, self.tolerance):
formatted = tuple(self.index_format.format(spaces[j], idx, concat_spin=False)
formatted = tuple(self.index_format.format(spaces[j], idx,
concat_spin=False)
for j, idx in enumerate(indices))
ret.append(tuple(zip(*formatted)) + (value, ))
return ret

def format(self, spaces, tensor):
"""
Return a multiline string representing the dominant tensor elements.
The tensor index is formatted according to the index format passed upon class
construction.
The tensor index is formatted according to the index format passed
upon class construction.
"""
ret = []
for indices, spins, value in self.format_as_list(spaces, tensor):
Expand Down
29 changes: 15 additions & 14 deletions adcc/FormatIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _translate_index(self, space, idx):
def optimise_formatting(self, space_index_pairs):
"""
Optimise the formatting parameters of this class in order to be able to
nicely produce equivalently formatted tensor format strings for all the passed
spaces-index pairs.
nicely produce equivalently formatted tensor format strings for all the
passed spaces-index pairs.
This function can be called multiple times.
"""
Expand All @@ -93,8 +93,8 @@ def format(self, space, idx, concat_spin=True):
@property
def max_n_characters(self):
"""
The maximum number of characters needed for a formatted index (excluding the "a"
or "b" spin string) according to the current optimised formatting.
The maximum number of characters needed for a formatted index (excluding
the "a" or "b" spin string) according to the current optimised formatting.
"""
return self.max_digits

Expand Down Expand Up @@ -132,8 +132,8 @@ def _translate_index(self, space, idx):
def optimise_formatting(self, space_index_pairs):
"""
Optimise the formatting parameters of this class in order to be able to
nicely produce equivalently formatted tensor format strings for all the passed
spaces-index pairs.
nicely produce equivalently formatted tensor format strings for all the
passed spaces-index pairs.
This function can be called multiple times.
"""
Expand All @@ -154,8 +154,8 @@ def format(self, space, idx, concat_spin=True):
@property
def max_n_characters(self):
"""
The maximum number of characters needed for a formatted index (excluding the "a"
or "b" spin string) according to the current optimised formatting.
The maximum number of characters needed for a formatted index (excluding
the "a" or "b" spin string) according to the current optimised formatting.
"""
return 5 + self.max_digits

Expand Down Expand Up @@ -198,8 +198,9 @@ def __init__(self, refstate, max_digits=1, use_hoco=True):
# TODO Expand this class there is something sensible
closed_shell = refstate.n_alpha == refstate.n_beta
if not refstate.is_aufbau_occupation or not closed_shell:
raise ValueError("format_homolumo only produces the right results for "
"closed-shell references with an Aufbau occupation")
raise ValueError("format_homolumo only produces the right results "
"for closed-shell references with an Aufbau "
"occupation")

def _translate_index(self, space, idx):
# Deal with core-occupied orbitals first:
Expand Down Expand Up @@ -238,8 +239,8 @@ def _translate_index(self, space, idx):
def optimise_formatting(self, space_index_pairs):
"""
Optimise the formatting parameters of this class in order to be able to
nicely produce equivalently formatted tensor format strings for all the passed
spaces-index pairs.
nicely produce equivalently formatted tensor format strings for all the
passed spaces-index pairs.
This function can be called multiple times.
"""
Expand All @@ -258,7 +259,7 @@ def format(self, space, idx, concat_spin=True):
@property
def max_n_characters(self):
"""
The maximum number of characters needed for a formatted index (excluding the "a"
or "b" spin string) according to the current optimised formatting.
The maximum number of characters needed for a formatted index (excluding
the "a" or "b" spin string) according to the current optimised formatting.
"""
return 4 + self.maxlen_offset
22 changes: 12 additions & 10 deletions adcc/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def available():
if not __status:
status = {
"pyscf": is_module_available("pyscf", "1.5.0"),
"psi4": is_module_available("psi4", "1.2.1") and is_module_available("psi4.core"),
"veloxchem": is_module_available("veloxchem"), # Exports no version info
"molsturm": is_module_available("molsturm"), # Exports no version info
"psi4": (is_module_available("psi4", "1.3.0")
and is_module_available("psi4.core")),
"veloxchem": is_module_available("veloxchem"), # No version info
"molsturm": is_module_available("molsturm"), # No version info
}
return sorted([b for b in status if status[b]])

Expand Down Expand Up @@ -141,8 +142,7 @@ def import_scf_results(res):
"type " + str(type(res)) + " implemented.")


def run_hf(backend=None, xyz=None, basis="sto-3g", charge=0, multiplicity=1,
conv_tol=1e-12, conv_tol_grad=1e-8, max_iter=150):
def run_hf(backend, xyz, basis, **kwargs):
"""
Run a HF calculation with a specified backend, molecule, and SCF
parameters
Expand All @@ -164,7 +164,8 @@ def run_hf(backend=None, xyz=None, basis="sto-3g", charge=0, multiplicity=1,
if len(available()) == 0:
raise RuntimeError(
"No supported host-program available as SCF backend. "
"See https://adc-connect.org/installation.html#install-hostprogram "
"See https://adc-connect.org/latest/"
"installation.html#install-hostprogram "
"for installation instructions."
)
else:
Expand All @@ -175,17 +176,18 @@ def run_hf(backend=None, xyz=None, basis="sto-3g", charge=0, multiplicity=1,
raise ValueError("Backend {} not found.".format(backend))
if backend == "psi4":
from . import psi4 as backend_hf

elif backend == "pyscf":
from . import pyscf as backend_hf

elif backend == "veloxchem":
from . import veloxchem as backend_hf

elif backend == "molsturm":
from . import molsturm as backend_hf

else:
raise NotImplementedError("No run_hf function implemented for backend "
"{}.".format(backend))

return backend_hf.run_hf(
xyz, basis, charge, multiplicity, conv_tol,
conv_tol_grad, max_iter
)
return backend_hf.run_hf(xyz, basis, **kwargs)
Loading

0 comments on commit ea25250

Please sign in to comment.