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

Excited states solver #437

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
711822c
Add solver for excited states, compiling but not running
Gabrielgerez Nov 10, 2022
ddd7dd3
excited state solver running and converging to a number
Gabrielgerez Nov 10, 2022
80ff2be
Computing correct first excited energy of a
Gabrielgerez Nov 18, 2022
036a27a
fix bracket typo
Gabrielgerez Nov 21, 2022
c405bd4
Use trace() instead of digonal().sum() in computeOmega
Gabrielgerez Nov 24, 2022
ab269cc
Only ever compute gamma, keep update schemes for future reference
Gabrielgerez Nov 24, 2022
9555d82
clang format
Gabrielgerez Nov 24, 2022
7862bf9
Add two state solver, seg faults
Gabrielgerez Nov 21, 2022
4f24833
fix rebase error
Gabrielgerez Nov 24, 2022
3ac4c47
Generalize to multiple states, converges for single state but doesn't…
Gabrielgerez Nov 28, 2022
dfb27c3
Can properly converge 3 states in one calculation.
Gabrielgerez Nov 29, 2022
67eb96e
Add own section for excited states, seg. faults
Gabrielgerez Dec 7, 2022
b422879
Revert "Add own section for excited states, seg. faults"
Gabrielgerez Jan 9, 2023
d245b8f
Include exc_solver to mrchem mid debug, Converges three states.
Gabrielgerez Dec 19, 2022
13764ba
Working ExcitedStatesSolver. Pol. tests failing
Gabrielgerez Jan 9, 2023
ce2612c
squash commit
Gabrielgerez Jan 18, 2023
00d1998
Add better reference to excited states test
Gabrielgerez Jan 19, 2023
132e63c
debugging for two orb tda
Gabrielgerez Mar 13, 2023
8102dbc
debug commit
Gabrielgerez Apr 11, 2023
ec5601e
debug commit
Gabrielgerez Apr 11, 2023
21e1177
TDA finally working for more than one orbital. Attempting trans. moms.
Gabrielgerez Jun 15, 2023
3603180
better transition moments equations, still off@
Gabrielgerez Jun 15, 2023
2f34e6a
update h2 reference, prepare for refactor
Gabrielgerez Jun 19, 2023
9e9aa79
Proper factor for transition moments
Gabrielgerez Jun 20, 2023
15b7814
more debug print statements
Gabrielgerez Jun 22, 2023
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
71 changes: 52 additions & 19 deletions doc/users/user_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ User input reference

**Default** ``False``

:excited_states: Compute excited states.

**Type** ``bool``

**Default** ``False``

:geometric_derivative: Compute geometric derivative.

**Type** ``bool``
Expand Down Expand Up @@ -443,6 +449,33 @@ User input reference
**Predicates**
- ``len(value) == 0 or len(value) == 3``

:ExcitedStates: Give details regarding the excited states calculation.

:red:`Keywords`
:n_states: Amount of states to solve for in the excited state solver.

**Type** ``int``

**Default** ``1``

:run_tda: What approximation to use to solve for the excited states.

**Type** ``bool``

**Default** ``False``

:kain: Length of KAIN iterative history.

**Type** ``int``

**Default** ``5``

:max_iter: Maximum number of SCF iterations.

**Type** ``int``

**Default** ``100``

:Polarizability: Give details regarding the polarizability calculation.

:red:`Keywords`
Expand Down Expand Up @@ -494,109 +527,109 @@ User input reference

**Default** ``initial_guess/mrchem.mob``

:guess_phi_p: File name for paired orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/phi_p_scf_idx_<0...Np>_<re/im>.mw
:guess_phi_p: File name for paired orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/phi_p_scf_idx_<0...Np>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/phi_p``

:guess_phi_a: File name for alpha orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/phi_a_scf_idx_<0...Na>_<re/im>.mw
:guess_phi_a: File name for alpha orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/phi_a_scf_idx_<0...Na>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/phi_a``

:guess_phi_b: File name for beta orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/phi_b_scf_idx_<0...Nb>_<re/im>.mw
:guess_phi_b: File name for beta orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/phi_b_scf_idx_<0...Nb>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/phi_b``

:guess_x_p: File name for paired response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/x_p_rsp_idx_<0...Np>_<re/im>.mw
:guess_x_p: File name for paired response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/x_p_rsp_idx_<0...Np>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/X_p``

:guess_x_a: File name for alpha response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/x_a_rsp_idx_<0...Na>_<re/im>.mw
:guess_x_a: File name for alpha response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/x_a_rsp_idx_<0...Na>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/X_a``

:guess_x_b: File name for beta response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/x_b_rsp_idx_<0...Nb>_<re/im>.mw
:guess_x_b: File name for beta response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/x_b_rsp_idx_<0...Nb>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/X_b``

:guess_y_p: File name for paired response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/y_p_rsp_idx_<0...Np>_<re/im>.mw
:guess_y_p: File name for paired response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/y_p_rsp_idx_<0...Np>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/Y_p``

:guess_y_a: File name for alpha response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/y_a_rsp_idx_<0...Na>_<re/im>.mw
:guess_y_a: File name for alpha response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/y_a_rsp_idx_<0...Na>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/Y_a``

:guess_y_b: File name for beta response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/y_b_rsp_idx_<0...Nb>_<re/im>.mw
:guess_y_b: File name for beta response orbitals, used with ``mw`` guess. Expected path is ``<path_orbitals>/y_b_rsp_idx_<0...Nb>_<re/im>.mw``

**Type** ``str``

**Default** ``initial_guess/Y_b``

:guess_cube_p: File name for paired orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/phi_p_scf_idx_<0...Np>_<re/im>.cube where `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_p: File name for paired orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/phi_p_scf_idx_<0...Np>_<re/im>.cube`` where ``Np`` is the number of orbitals and `re/im` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/phi_p``

:guess_cube_a: File name for alpha orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/phi_a_scf_idx_<0...Na>_<re/im>.cube where `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_a: File name for alpha orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/phi_a_scf_idx_<0...Na>_<re/im>.cube`` where ``Np`` is the number of orbitals and `re/im` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/phi_a``

:guess_cube_b: File name for beta orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/phi_b_scf_idx_<0...Nb>_<re/im>.cube where `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_b: File name for beta orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/phi_b_scf_idx_<0...Nb>_<re/im>.cube`` where ``Np`` is the number of orbitals and `re/im` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/phi_b``

:guess_cube_x_p: File name for paired response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/x_p_rsp_<0,1,2>_<0...Np>_<re/im>.cube where `0,1,2` indicate the index of the components of the response vectors. `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_x_p: File name for paired response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/x_p_<rsp,exc>_<0,1,2,...,N>_<0...Np>_<re/im>.cube`` This can be an initial guess for two types of calculations, `exc`for excited states and `rsp` for a response calculation. If ``exc`` is used, the second set of variables ``1,2,...,N`` indicates which state this is a guess for. If ``rsp`` is used, the second set of variables ``1,2,...,N`` indicates the component of the response vectors. ``Np`` is the number of orbitals and ``re/im`` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/x_p``

:guess_cube_x_a: File name for alpha response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/x_a_rsp_<0,1,2>_<0...Na>_<re/im>.cube where `0,1,2` indicate the index of the components of the response vectors. `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_x_a: File name for alpha response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/x_a_<rsp,exc>_<0,1,2,...,N>_<0...Na>_<re/im>.cube`` This can be an initial guess for two types of calculations, `exc`for excited states and `rsp` for a response calculation. If ``exc`` is used, the second set of variables ``1,2,...,N`` indicates which state this is a guess for. If ``rsp`` is used, the second set of variables ``1,2,...,N`` indicates the component of the response vectors. ``Np`` is the number of orbitals and ``re/im`` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/x_a``

:guess_cube_x_b: File name for beta response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/x_b_rsp_<0,1,2>_<0...Nb>_<re/im>.cube where `0,1,2` indicate the index of the components of the response vectors. `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_x_b: File name for beta response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/x_b_<rsp,exc>_<0,1,2,...,N>_<0...Nb>_<re/im>.cube`` This can be an initial guess for two types of calculations, `exc`for excited states and `rsp` for a response calculation. If ``exc`` is used, the second set of variables ``1,2,...,N`` indicates which state this is a guess for. If ``rsp`` is used, the second set of variables ``1,2,...,N`` indicates the component of the response vectors. ``Np`` is the number of orbitals and ``re/im`` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/x_b``

:guess_cube_y_p: File name for paired response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/y_p_rsp_<0,1,2>_<0...Np>_<re/im>.cube where `0,1,2` indicate the index of the components of the response vectors. `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_y_p: File name for paired response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/y_p_<rsp,exc>_<0,1,2,...,N>_<0...Np>_<re/im>.cube`` This can be an initial guess for two types of calculations, `exc`for excited states and `rsp` for a response calculation. If ``exc`` is used, the second set of variables ``1,2,...,N`` indicates which state this is a guess for. If ``rsp`` is used, the second set of variables ``1,2,...,N`` indicates the component of the response vectors. ``Np`` is the number of orbitals and ``re/im`` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/y_p``

:guess_cube_y_a: File name for alpha response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/y_a_rsp_<0,1,2>_<0...Na>_<re/im>.cube where `0,1,2` indicate the index of the components of the response vectors. `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_y_a: File name for alpha response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/y_a_<rsp,exc>_<0,1,2,...,N>_<0...Na>_<re/im>.cube`` This can be an initial guess for two types of calculations, `exc`for excited states and `rsp` for a response calculation. If ``exc`` is used, the second set of variables ``1,2,...,N`` indicates which state this is a guess for. If ``rsp`` is used, the second set of variables ``1,2,...,N`` indicates the component of the response vectors. ``Np`` is the number of orbitals and ``re/im`` denote real or imaginary parts.

**Type** ``str``

**Default** ``initial_guess/y_a``

:guess_cube_y_b: File name for beta response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/y_b_rsp_<0,1,2>_<0...Nb>_<re/im>.cube where `0,1,2` indicate the index of the components of the response vectors. `Np` is the number of orbitals and `re/im` denote real or imaginary parts.
:guess_cube_y_b: File name for beta response orbitals, used with ``cube`` guess. Expected path is ``<path_orbitals>/y_b_<rsp,exc>_<0,1,2,...,N>_<0...Nb>_<re/im>.cube`` This can be an initial guess for two types of calculations, `exc`for excited states and `rsp` for a response calculation. If ``exc`` is used, the second set of variables ``1,2,...,N`` indicates which state this is a guess for. If ``rsp`` is used, the second set of variables ``1,2,...,N`` indicates the component of the response vectors. ``Np`` is the number of orbitals and ``re/im`` denote real or imaginary parts.

**Type** ``str``

Expand Down Expand Up @@ -767,7 +800,7 @@ User input reference
**Predicates**
- ``1.0e-10 < value < 1.0``

:guess_type: Type of initial guess for response. ``none`` will start from a zero guess for the response functions. ``chk`` restarts a previous calculation which was dumped using the ``write_checkpoint`` keyword. ``mw`` will start from final orbitals in a previous calculation written using the ``write_orbitals`` keyword. The orbitals will be re-projected into the new computational setup.
:guess_type: Type of initial guess for response. ``none`` will start from a zero guess for the response functions. ``chk`` restarts a previous calculation which was dumped using the ``write_checkpoint`` keyword. ``mw`` will start from final orbitals in a previous calculation written using the ``write_orbitals`` keyword. The orbitals will be re-projected into the new computational setup. ``cube`` will start from orbitals saved in cubefiles from external calculations.

**Type** ``str``

Expand Down
20 changes: 13 additions & 7 deletions python/mrchem/CUBEparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .input_parser.plumbing import pyparsing as pp


def parse_files(user_dict, direction=None):
def parse_files(user_dict, direction=None, state=None):

file_dict = user_dict["Files"]
world_unit = user_dict["world_unit"]
Expand All @@ -41,12 +41,15 @@ def parse_files(user_dict, direction=None):
found = False
for key, val in cube_guess_dict.items():
if (direction is not None):
data_type = "_".join(key.split("_")[2:]) + f"_{direction:d}"
data_type = "_".join(key.split("_")[2:]) + f"_rsp_{direction:d}"
path_list = _get_paths(Path(val), rsp=True, direction=direction)
elif (state is not None):
data_type = "_".join(key.split("_")[2:]) + f"_exc_{state:d}"
path_list = _get_paths(Path(val), exc=True, state=state)
else:
data_type = "_".join(key.split("_")[2:])
path_list = _get_paths(Path(val))

if path_list:
found = found or True
_write_cube_vectors(path_list, data_type, world_unit, pc, vector_dir)
Expand All @@ -58,7 +61,6 @@ def parse_files(user_dict, direction=None):

def _write_cube_vectors(path_list, data_type, world_unit, pc, vector_dir):
cube_list = []

if not vector_dir.is_dir():
vector_dir.mkdir()

Expand All @@ -75,15 +77,19 @@ def _write_cube_vectors(path_list, data_type, world_unit, pc, vector_dir):
fd.write(dumps(cube_list, indent=2))


def _get_paths(path, rsp=False, direction=None):
def _get_paths(path, rsp=False, exc=False, direction=None, state=None):
directory = path.parent
prefix = path.name if (not rsp) else f"{path.name}_rsp_{direction:d}"
prefix = path.name
if (rsp):
prefix = f"{path.name}_rsp_{direction:d}"
elif (exc):
prefix = f"{path.name}_exc_{state:d}"


if directory.is_dir():
path_l = [file.resolve() for file in directory.glob(f"{prefix}*.cube")]
else:
path_l = []

return path_l


Expand Down
6 changes: 5 additions & 1 deletion python/mrchem/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
write_scf_properties,
write_scf_plot,
write_rsp_calc,
write_exc_calc,
parse_wf_method,
)
from .periodictable import PeriodicTable as PT, PeriodicTableByZ as PT_Z
Expand Down Expand Up @@ -179,8 +180,8 @@ def write_rsp_calculations(user_dict, mol_dict, origin):
run_pol = user_dict["Properties"]["polarizability"]
run_mag = user_dict["Properties"]["magnetizability"]
run_nmr = user_dict["Properties"]["nmr_shielding"]
run_exc = user_dict["Properties"]["excited_states"]
nuc_spec = user_dict["NMRShielding"]["nuclear_specific"]

if run_pol:
for omega in user_dict["Polarizability"]["frequency"]:
freq_key = f"{omega:6f}"
Expand Down Expand Up @@ -268,5 +269,8 @@ def write_rsp_calculations(user_dict, mol_dict, origin):
}
rsp_key = "nuc_mag-" + atom_key
rsp_dict[rsp_key] = rsp_calc

if run_exc:
rsp_dict["excited_states"] = write_exc_calc(user_dict, origin)

return rsp_dict
Loading