├── .coveragerc
├── .github
└── workflows
│ ├── ci.yaml
│ └── publish.yaml
├── .gitignore
├── .lgtm.yml
├── LICENSE
├── MANIFEST.in
├── README.md
├── adcc
├── AdcMatrix.py
├── AdcMethod.py
├── AmplitudeVector.py
├── DataHfProvider.py
├── ElectronicTransition.py
├── Excitation.py
├── ExcitedStates.py
├── FormatDominantElements.py
├── FormatIndex.py
├── HfCounterData.py
├── Intermediates.py
├── IsrMatrix.py
├── LazyMp.py
├── MoSpaces.py
├── OneParticleOperator.py
├── OperatorIntegrals.py
├── ReferenceState.py
├── State2States.py
├── Symmetry.py
├── Tensor.py
├── __init__.py
├── adc_pp
│ ├── __init__.py
│ ├── bmatrix.py
│ ├── environment.py
│ ├── matrix.py
│ ├── modified_transition_moments.py
│ ├── state2state_transition_dm.py
│ ├── state_diffdm.py
│ ├── transition_dm.py
│ └── util.py
├── backends
│ ├── EriBuilder.py
│ ├── __init__.py
│ ├── molsturm.py
│ ├── psi4.py
│ ├── pyscf.py
│ └── veloxchem.py
├── block.py
├── exceptions.py
├── functions.py
├── guess
│ ├── __init__.py
│ ├── guess_zero.py
│ └── guesses_from_diagonal.py
├── hdf5io.py
├── memory_pool.py
├── misc.py
├── opt_einsum_integration.py
├── projection.py
├── setup_environment.sh
├── solver
│ ├── LanczosIterator.py
│ ├── SolverStateBase.py
│ ├── __init__.py
│ ├── common.py
│ ├── conjugate_gradient.py
│ ├── davidson.py
│ ├── explicit_symmetrisation.py
│ ├── lanczos.py
│ ├── orthogonaliser.py
│ ├── power_method.py
│ └── preconditioner.py
├── tests
│ ├── AdcMatrix_block_view_test.py
│ ├── AdcMatrix_dense_export_test.py
│ ├── AdcMatrix_test.py
│ ├── AmplitudeVector_test.py
│ ├── DataHfProvider_test.py
│ ├── ExcitedStates_test.py
│ ├── HartreeFockProvider_test.py
│ ├── IsrMatrix_test.py
│ ├── LazyMp_test.py
│ ├── OneParticleOperator_test.py
│ ├── ReferenceState_backends_test.py
│ ├── ReferenceState_counterdata_test.py
│ ├── ReferenceState_refdata_test.py
│ ├── ReferenceState_test.py
│ ├── Tensor_test.py
│ ├── __init__.py
│ ├── adc_pp
│ │ ├── __init__.py
│ │ └── modified_transition_moments_test.py
│ ├── backends
│ │ ├── __init__.py
│ │ ├── backends_crossref_test.py
│ │ ├── backends_pcm_test.py
│ │ ├── backends_polembed_test.py
│ │ ├── molsturm_test.py
│ │ ├── psi4_test.py
│ │ ├── pyscf_test.py
│ │ ├── testing.py
│ │ └── veloxchem_test.py
│ ├── conftest.py
│ ├── data
│ │ ├── .gitignore
│ │ ├── SHA256SUMS
│ │ ├── make_shasums.sh
│ │ ├── psi4_data.json
│ │ ├── pyscf_data.json
│ │ ├── remove_testdata.py
│ │ ├── tmole_data.json
│ │ └── update_testdata.sh
│ ├── direct_sum_test.py
│ ├── einsum_test.py
│ ├── functionality_test.py
│ ├── functionality_xes_test.py
│ ├── generators
│ │ ├── __init__.py
│ │ ├── dump_adcc.py
│ │ ├── dump_pyscf.py
│ │ ├── generate_adcc_data.py
│ │ ├── generate_adcman_data.py
│ │ ├── generate_hfdata.py
│ │ ├── generate_hfimport.py
│ │ ├── generate_psi4_data.py
│ │ ├── generate_pyscf_data.py
│ │ ├── import_qchem_data.py
│ │ ├── potentials
│ │ │ └── fa_6w.pot
│ │ ├── qchem_savedir.py
│ │ └── run_qchem.py
│ ├── guess_test.py
│ ├── hardcoded_test.py
│ ├── misc_test.py
│ ├── projection_test.py
│ ├── properties_test.py
│ ├── smoke_test.py
│ ├── solver
│ │ ├── __init__.py
│ │ ├── conjugate_gradient_test.py
│ │ ├── davidson_test.py
│ │ ├── lanczos_test.py
│ │ └── power_method_test.py
│ ├── state_densities_test.py
│ ├── testcases.py
│ ├── testdata_cache.py
│ └── workflow_test.py
├── timings.py
├── visualisation
│ ├── ExcitationSpectrum.py
│ ├── Spectrum.py
│ ├── __init__.py
│ └── shapefctns.py
└── workflow.py
├── codecov.yml
├── conda
└── environment.yml
├── docs
├── .gitignore
├── Doxyfile
├── about.rst
├── benchmarks.rst
├── benchmarks
│ ├── MethylammoniumRadical.rst
│ ├── Noradrenaline.rst
│ ├── ParaNitroAniline.rst
│ ├── PhosphineCvs.rst
│ ├── WaterExpensive.rst
│ ├── commit.rst
│ └── update.py
├── calculations.rst
├── conf.py
├── developers.rst
├── hostprograms.rst
├── images
│ ├── ecd_methyloxirane.png
│ ├── generate_plot_spectrum_water.py
│ ├── matrix
│ │ ├── .gitignore
│ │ ├── adc_matrix_schematic.png
│ │ ├── generate_matrices.py
│ │ ├── matrix_water_adc2_sto3g.png
│ │ └── matrix_water_adc3_sto3g.png
│ ├── plot_spectrum_water.png
│ └── setup_environment.sh
├── index.rst
├── installation.rst
├── logo
│ ├── .gitignore
│ ├── logo.pdf
│ ├── logo.png
│ ├── logo.tex
│ └── make_logo.sh
├── pub.bib
├── ref.bib
├── reference.rst
├── theory.rst
├── topics.rst
└── zpublications.rst
├── environment.yml
├── examples
├── .gitignore
├── 0_basics
│ ├── 00_Overview.ipynb
│ ├── 01_Backends.ipynb
│ ├── 02_Theory.ipynb
│ ├── 03_Tweaks.ipynb
│ └── h2o_sto3g_hfdata.hdf5
├── 2_core_excitations
│ └── water_core_by_projection.py
├── environment
│ ├── pna_6w.pot
│ ├── psi4_adc2_pna_6w_pol_embed.py
│ ├── psi4_adc2_pna_ptlr_ddx.py
│ ├── psi4_adc2_pna_ptlr_pcm.py
│ ├── psi4_adc2_pna_ss_ddx.py
│ ├── pyscf_adc2_pna_6w_pol_embed.py
│ ├── pyscf_adc2_pna_lr_pcm.py
│ └── setup_environment.sh
├── hydrogen_fluoride
│ ├── .gitignore
│ ├── psi4_631g_sf_adc2.py
│ ├── pyscf_631g_sf_adc2.py
│ └── pyscf_631g_sf_adc2_dissociation.py
├── methyloxirane
│ ├── pyscf_631g_adc2_ecd.py
│ └── setup_environment.sh
├── neon
│ ├── setup_environment.sh
│ └── test_cg_alpha.py
├── sulfur_hydride
│ ├── pyscf_ccpvtz_arbitrary_cvs_adc2x.py
│ ├── pyscf_ccpvtz_fc_cvs_adc2x.py
│ └── pyscf_geoopt_mp2.py
└── water
│ ├── .gitignore
│ ├── data.py
│ ├── import_data.py
│ ├── molsturm_sto3g_adc2.py
│ ├── psi4_adc_cascade.ipynb
│ ├── psi4_ccpvdz_adc2_spectrum.py
│ ├── psi4_ccpvdz_cvs_adc2.py
│ ├── psi4_sto3g_adc2.py
│ ├── psi4_sto3g_uhf_adc2.py
│ ├── pyscf_ccpvdz_adc2_ao_properties.py
│ ├── pyscf_ccpvdz_adc2_spectrum.py
│ ├── pyscf_ccpvdz_adc3_comparison.py
│ ├── pyscf_ccpvdz_fc_adc3.py
│ ├── pyscf_ccpvdz_fv_adc3.py
│ ├── pyscf_ccpvdz_xes.py
│ ├── pyscf_ccpvtz_adc3.py
│ ├── pyscf_sto3g_adc1.py
│ ├── pyscf_sto3g_adc2.jl
│ ├── pyscf_sto3g_adc2.py
│ ├── pyscf_sto3g_uhf_adc2.py
│ ├── setup_environment.sh
│ ├── sto3g_adc1.py
│ ├── sto3g_adc2.py
│ ├── sto3g_adc2x.py
│ ├── sto3g_adc3.py
│ ├── sto3g_cvs_adc2.py
│ ├── sto3g_fc_adc2.py
│ ├── sto3g_uadc2.py
│ ├── tpa.py
│ ├── veloxchem_ccpvdz_adc2_spectrum.py
│ └── veloxchem_sto3g_adc2.py
├── libadcc
├── .clang-format
├── .ycm_extra_conf.py
├── AdcMemory.cc
├── AdcMemory.hh
├── AxisInfo.cc
├── AxisInfo.hh
├── HartreeFockSolution_i.hh
├── MoIndexTranslation.cc
├── MoIndexTranslation.hh
├── MoSpaces.cc
├── MoSpaces.hh
├── MoSpaces
│ ├── construct_blocks.cc
│ ├── construct_blocks.hh
│ ├── setup_point_group_table.cc
│ └── setup_point_group_table.hh
├── ReferenceState.cc
├── ReferenceState.hh
├── Symmetry.cc
├── Symmetry.hh
├── Tensor.cc
├── Tensor.hh
├── TensorImpl.cc
├── TensorImpl.hh
├── TensorImpl
│ ├── ExpressionTree.cc
│ ├── ExpressionTree.hh
│ ├── as_bispace.cc
│ ├── as_bispace.hh
│ ├── as_lt_symmetry.cc
│ ├── as_lt_symmetry.hh
│ ├── get_block_starts.cc
│ ├── get_block_starts.hh
│ └── instantiate_valid.py
├── ThreadPool.cc
├── ThreadPool.hh
├── Timer.cc
├── Timer.hh
├── amplitude_vector_enforce_spin_kind.cc
├── amplitude_vector_enforce_spin_kind.hh
├── backend.cc
├── backend.hh
├── config.hh
├── exceptions.hh
├── fill_pp_doubles_guesses.cc
├── fill_pp_doubles_guesses.hh
├── guess
│ ├── adc_guess_d.cc
│ ├── adc_guess_d.hh
│ ├── index_group_d.cc
│ └── index_group_d.hh
├── import_eri.cc
├── import_eri.hh
├── make_symmetry.cc
├── make_symmetry.hh
├── pyiface
│ ├── ExportAdcc.cc
│ ├── export_AdcMemory.cc
│ ├── export_HartreeFockProvider.cc
│ ├── export_MoIndexTranslation.cc
│ ├── export_MoSpaces.cc
│ ├── export_ReferenceState.cc
│ ├── export_Symmetry.cc
│ ├── export_Tensor.cc
│ ├── export_adc_pp.cc
│ ├── export_threading.cc
│ ├── hartree_fock_solution_hack.hh
│ ├── util.cc
│ └── util.hh
├── shape_to_string.cc
├── shape_to_string.hh
└── tests
│ ├── HFSolutionMock.hh
│ ├── MoIndexTranslationTest.cc
│ ├── MoSpacesTest.cc
│ ├── TensorTest.cc
│ ├── TensorTestData.cc
│ ├── TensorTestData.hh
│ ├── generate_TensorTestData.cc.py
│ ├── main.cc
│ ├── output_tensor.hh
│ ├── random_tensor.cc
│ ├── random_tensor.hh
│ └── wrap_libtensor.hh
├── requirements.txt
├── scripts
├── .gitignore
├── load_libtensor.py
├── remove_test_files.sh
├── upload_documentation.py
└── upload_to_pypi.sh
├── setup.cfg
├── setup.py
├── siteconfig_example.py
└── templates
├── README.md
├── cc.template
├── cmake.template
├── hh.template
├── py.template
└── tmpl_settings.vim
/.coveragerc:
--------------------------------------------------------------------------------
1 | [run]
2 | branch = True
3 | source = adcc
4 | omit = adcc/tests/*
5 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yaml:
--------------------------------------------------------------------------------
1 | name: Publish package
2 | on:
3 | push:
4 | branches: [master]
5 | tags: ['v*']
6 | workflow_dispatch:
7 |
8 | jobs:
9 | publish_pypi:
10 | name: Publish 📦 to PyPI
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v4
14 | - uses: actions/setup-python@v5
15 | with:
16 | python-version: '3.9'
17 | - name: Install dependencies
18 | run: |
19 | sudo apt-get install libopenblas-dev
20 | python -m pip install --user pyscf cppe wheel
21 | python -m pip install --user -r requirements.txt
22 | - name: Install package
23 | run: |
24 | python -m pip install --user .[tests]
25 | - name: Run python tests
26 | run: |
27 | python -m pytest
28 | - name: Build a source tarball
29 | # in the future...
30 | # run: python -m build --sdist
31 | run: python setup.py sdist
32 | - name: Publish distribution 📦 to PyPI
33 | if: startsWith(github.ref, 'refs/tags')
34 | uses: pypa/gh-action-pypi-publish@master
35 | with:
36 | user: __token__
37 | password: ${{ secrets.pypi_password }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Backup files and system temporaries
2 | *~
3 | .*.swp
4 | *.swo
5 |
6 | # compiled files and distribution files
7 | *.pyc
8 | /build
9 | *.o
10 | /libadcc.*.so
11 | /libadcc.*.dylib
12 | /dist
13 | *.egg-info
14 | /.eggs
15 | /siteconfig.py
16 |
17 | # Testing
18 | .pytest_cache
19 | .coverage
20 |
21 | # Jupyter
22 | .ipynb_checkpoints/
23 |
24 | # psi4
25 | timer.dat
26 | *.clean
27 |
--------------------------------------------------------------------------------
/.lgtm.yml:
--------------------------------------------------------------------------------
1 | path_classifiers:
2 | template:
3 | - siteconfig_example.py
4 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | # Exclude test stuff
2 | exclude adcc/tests/**
3 | include adcc/tests/smoke_test.py
4 | global-include libadcc/**/*.hh libadcc/**/*.cc
5 | include LICENSE
6 | include README.md
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # adcc: Seamlessly connect your program to ADC
4 | | **Documentation** | [![][docs-img]][docs-url] [![][binder-img]][binder-url] |
5 | | :------ | :------- |
6 | | **Build Status** | [![][ci-img]][ci-url] [![][cov-img]][cov-url] [![][lgtm-img]][lgtm-url] |
7 | | **Installation** | [![][pypi-img]][pypi-url] [![][conda-img]][conda-url] [![][license-img]][license-url] |
8 |
9 | [docs-img]: https://img.shields.io/badge/doc-latest-blue.svg
10 | [docs-url]: https://adc-connect.org
11 | [binder-img]: https://mybinder.org/badge_logo.svg
12 | [binder-url]: https://try.adc-connect.org
13 | [ci-img]: https://github.com/adc-connect/adcc/workflows/CI/badge.svg?branch=master&event=push
14 | [ci-url]: https://github.com/adc-connect/adcc/actions
15 | [cov-img]: https://coveralls.io/repos/adc-connect/adcc/badge.svg?branch=master&service=github
16 | [cov-url]: https://coveralls.io/github/adc-connect/adcc?branch=master
17 | [license-img]: https://img.shields.io/badge/License-GPL%20v3-blue.svg
18 | [license-url]: https://github.com/adc-connect/adcc/blob/master/LICENSE
19 | [pypi-img]: https://img.shields.io/pypi/v/adcc
20 | [pypi-url]: https://pypi.org/project/adcc
21 | [conda-img]: https://anaconda.org/conda-forge/adcc/badges/version.svg
22 | [conda-url]: https://anaconda.org/conda-forge/adcc
23 | [lgtm-img]: https://img.shields.io/lgtm/grade/python/github/adc-connect/adcc?label=code%20quality
24 | [lgtm-url]: https://lgtm.com/projects/g/adc-connect/adcc/context:python
25 |
26 | adcc (**ADC-connect**) is a Python-based framework for calculating molecular spectra and electronically excited states
27 | with the algebraic-diagrammatic construction (ADC) approach.
28 |
29 | Arbitrary host programs may be used to supply a
30 | self-consistent field (SCF) reference to start off the ADC calculation.
31 | Currently adcc comes with ready-to-use interfaces to four programs: PySCF, Psi4, VeloxChem and molsturm.
32 | Adding other SCF codes or
33 | starting a calculation from
34 | statically computed data can be easily achieved.
35 |
36 | Try adcc in your browser at https://try.adc-connect.org
37 | or take a look at the [adcc documentation](https://adc-connect.org)
38 | for more details and installation instructions.
39 |
40 | ## Citation
41 |
42 | **Paper:** | [](https://doi.org/10.1002/wcms.1462)
43 | -----------| --------------------------------------------------------------------------------------------------------
44 | **Code:** | [](https://zenodo.org/badge/latestdoi/215731857)
45 |
46 | If you use adcc, please cite
47 | [our paper in WIREs Computational Molecular Science](https://doi.org/10.1002/wcms.1462).
48 | A preprint can be found
49 | [on HAL](https://hal.archives-ouvertes.fr/hal-02319517)
50 | or [on arXiv](http://arxiv.org/pdf/1910.07757).
51 |
--------------------------------------------------------------------------------
/adcc/Intermediates.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | from .timings import Timer
24 | from .functions import evaluate
25 |
26 |
27 | class Intermediates():
28 | """
29 | Class offering to return a number of intermediate tensors.
30 | The tensors are cached internally for later reuse
31 | """
32 | generators = {} # Registered generator functions
33 |
34 | def __init__(self, ground_state):
35 | self.ground_state = ground_state
36 | self.reference_state = ground_state.reference_state
37 | self.timer = Timer()
38 | self.cached_tensors = {} # Cached tensors
39 | # TODO Make caching configurable ??
40 |
41 | def __getattr__(self, key):
42 | if key in self.cached_tensors:
43 | return self.cached_tensors[key]
44 | elif key in self.generators:
45 | # Evaluate the tensor, all generators take (hf, mp, intermediates)
46 | generator = self.generators[key]
47 | with self.timer.record(key):
48 | tensor = generator(self.reference_state, self.ground_state, self)
49 | self.cached_tensors[key] = evaluate(tensor)
50 | return self.cached_tensors[key]
51 | else:
52 | raise AttributeError
53 |
54 | def clear(self):
55 | """Clear all cached tensors to free storage"""
56 | self.cached_tensors.clear()
57 |
58 | def __repr__(self):
59 | return (
60 | "AdcIntermediates(contains="
61 | + list(self.cached_tensors.keys()).join(",")
62 | + ")"
63 | )
64 |
65 |
66 | def register_as_intermediate(function):
67 | """
68 | This decorator allows to register a function such that it can
69 | be used to produce intermediates for storage in Intermediates.
70 | The rule of thumb is that this should only be used on expressions
71 | which are used in multiple places of the ADC code (e.g. properties
72 | and matrix, multiple ADC variants etc.)
73 | """
74 | Intermediates.generators[function.__name__] = function
75 | return function
76 |
--------------------------------------------------------------------------------
/adcc/Symmetry.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import libadcc
24 |
25 |
26 | class Symmetry(libadcc.Symmetry):
27 | def __init__(self, mospaces, space, permutations=None,
28 | spin_block_maps=None, spin_blocks_forbidden=None):
29 | if not isinstance(mospaces, libadcc.MoSpaces):
30 | raise TypeError("mospaces needs to be an MoSpaces instance.")
31 |
32 | super().__init__(mospaces, space)
33 | if permutations is not None:
34 | self.permutations = permutations
35 | if spin_block_maps is not None:
36 | self.spin_block_maps = spin_block_maps
37 | if spin_blocks_forbidden is not None:
38 | self.spin_blocks_forbidden = spin_blocks_forbidden
39 |
40 | def _repr_pretty_(self, pp, cycle):
41 | pp.text(self.describe())
42 |
--------------------------------------------------------------------------------
/adcc/adc_pp/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | from .state_diffdm import state_diffdm
24 | from .transition_dm import transition_dm
25 | from .state2state_transition_dm import state2state_transition_dm
26 | from .modified_transition_moments import modified_transition_moments
27 |
28 | """
29 | Submodule, which contains rather lengthy low-level kernels
30 | (e.g. matrix-vector products or working equations), which are called
31 | from the high-level objects in the adcc main module.
32 | """
33 |
34 | __all__ = ["state_diffdm", "state2state_transition_dm", "transition_dm",
35 | "modified_transition_moments"]
36 |
--------------------------------------------------------------------------------
/adcc/adc_pp/environment.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2021 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | from adcc import OneParticleOperator, AmplitudeVector
24 | from .matrix import AdcBlock
25 |
26 |
27 | def block_ph_ph_0_pe(hf, mp, intermediates):
28 | """
29 | Constructs an :py:class:`AdcBlock` that describes the
30 | linear response coupling to the polarizable environment
31 | from PE via a CIS-like transition density as described
32 | in 10.1021/ct300763v, eq 63. Since the contribution
33 | depends on the input amplitude itself,
34 | a diagonal term cannot be formulated.
35 | """
36 | op = hf.operators
37 |
38 | def apply(ampl):
39 | tdm = OneParticleOperator(mp, is_symmetric=False)
40 | tdm.vo = ampl.ph.transpose()
41 | vpe = op.pe_induction_elec(tdm)
42 | return AmplitudeVector(ph=vpe.ov)
43 | return AdcBlock(apply, 0)
44 |
45 |
46 | def block_ph_ph_0_pcm(hf, mp, intermediates):
47 | """
48 | Constructs an :py:class:`AdcBlock` that describes the
49 | linear response coupling to the polarizable environment
50 | from PCM via a CIS-like transition density as described
51 | in 10.1021/ct300763v, eq 63. Since the contribution
52 | depends on the input amplitude itself,
53 | a diagonal term cannot be formulated.
54 | """
55 | op = hf.operators
56 |
57 | def apply(ampl):
58 | tdm = OneParticleOperator(mp, is_symmetric=False)
59 | tdm.vo = ampl.ph.transpose()
60 | vpcm = op.pcm_potential_elec(tdm)
61 | return AmplitudeVector(ph=vpcm.ov)
62 | return AdcBlock(apply, 0)
63 |
--------------------------------------------------------------------------------
/adcc/adc_pp/util.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 |
24 |
25 | def check_singles_amplitudes(spaces, *amplitudes):
26 | check_have_singles_block(*amplitudes)
27 | check_singles_subspaces(spaces, *amplitudes)
28 |
29 |
30 | def check_doubles_amplitudes(spaces, *amplitudes):
31 | check_have_doubles_block(*amplitudes)
32 | check_doubles_subspaces(spaces, *amplitudes)
33 |
34 |
35 | def check_have_singles_block(*amplitudes):
36 | if any("ph" not in amplitude.blocks for amplitude in amplitudes):
37 | raise ValueError("ADC(0) level and "
38 | "beyond expects an excitation amplitude with a "
39 | "singles part.")
40 |
41 |
42 | def check_have_doubles_block(*amplitudes):
43 | if any("pphh" not in amplitude.blocks for amplitude in amplitudes):
44 | raise ValueError("ADC(2) level and "
45 | "beyond expects an excitation amplitude with a "
46 | "singles and a doubles part.")
47 |
48 |
49 | def check_singles_subspaces(spaces, *amplitudes):
50 | for amplitude in amplitudes:
51 | u1 = amplitude.ph
52 | if u1.subspaces != spaces:
53 | raise ValueError("Mismatch in subspaces singles part "
54 | f"(== {u1.subspaces}), where {spaces} "
55 | "was expected.")
56 |
57 |
58 | def check_doubles_subspaces(spaces, *amplitudes):
59 | for amplitude in amplitudes:
60 | u2 = amplitude.pphh
61 | if u2.subspaces != spaces:
62 | raise ValueError("Mismatch in subspaces doubles part "
63 | f"(== {u2.subspaces}), where "
64 | f"{spaces} was expected.")
65 |
--------------------------------------------------------------------------------
/adcc/block.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 |
24 |
25 | def __getattr__(attr):
26 | """
27 | Return a multi-dimensional block string like 'o1o2v1v1'
28 | when requesting the attribute 'ocvv'.
29 | """
30 | if any(c not in ["o", "v", "c"] for c in attr):
31 | raise AttributeError
32 | mapping = {"o": "o1", "v": "v1", "c": "o2"}
33 | return "".join(mapping[c] for c in attr)
34 |
--------------------------------------------------------------------------------
/adcc/exceptions.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 |
24 |
25 | class InputError(ValueError):
26 | """
27 | Exception thrown during the validation stage of the arguments passed to
28 | :py:`run_adc` to signal that an input is not valid.
29 | """
30 | pass
31 |
32 |
33 | class InvalidReference(InputError):
34 | """
35 | Exception thrown if a passed SCF reference is invalid, e.g. because
36 | a feature like density-fitting has been applied, which is inconsistent
37 | with the current capabilities of adcc.
38 | """
39 | pass
40 |
--------------------------------------------------------------------------------
/adcc/memory_pool.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2018 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import os
24 | import glob
25 | import atexit
26 | import shutil
27 | import libadcc
28 | import tempfile
29 |
30 |
31 | class MemoryPool(libadcc.AdcMemory):
32 | def initialise(self, scratch_directory="/tmp", max_block_size=16,
33 | allocator="standard"):
34 | """Initialise the adcc memory management.
35 |
36 | Parameters
37 | ----------
38 | scratch_directory : str, optional
39 | Directory for storing temporary pagefiles. This should be a fast
40 | storage location as tensor data will be mapped to asynchronously
41 | to this directory for the "libxc" allocator.
42 |
43 | max_block_size : int, optional
44 | The maximal size a tensor block may have along each axis.
45 |
46 | allocator : str, optional
47 | The allocator to be used. Valid values are "libxm" or "standard"
48 | (libstc++ allocator).
49 | """
50 | pagefile_directory = tempfile.mkdtemp(prefix="adcc_", dir=scratch_directory)
51 | super().initialise(pagefile_directory, max_block_size, allocator)
52 | atexit.register(MemoryPool.cleanup, self)
53 |
54 | def cleanup(self):
55 | if os.path.isdir(self.pagefile_directory):
56 | shutil.rmtree(self.pagefile_directory)
57 |
58 | @property
59 | def scratch_directory(self):
60 | return os.path.dirname(self.pagefile_directory)
61 |
62 | @property
63 | def page_files(self):
64 | """The list of all page files."""
65 | globs = ["pagefile.*", "xmpagefile"]
66 | globs = [os.path.join(self.pagefile_directory, pat) for pat in globs]
67 | return [c for pat in globs for c in glob.glob(pat)]
68 |
69 | @property
70 | def total_size_page_files(self):
71 | """The total size of all page files."""
72 | return sum(os.path.getsize(f) for f in self.page_files)
73 |
74 |
75 | # The actual memory object to use
76 | memory_pool = MemoryPool()
77 |
--------------------------------------------------------------------------------
/adcc/setup_environment.sh:
--------------------------------------------------------------------------------
1 | for dir in ../build/src/adcc; do
2 | export PYTHONPATH="$PYTHONPATH:$(readlink -f "$dir")"
3 | done
4 |
--------------------------------------------------------------------------------
/adcc/solver/__init__.py:
--------------------------------------------------------------------------------
1 | from . import davidson
2 | from .SolverStateBase import EigenSolverStateBase
3 | from .explicit_symmetrisation import (IndexSpinSymmetrisation,
4 | IndexSymmetrisation)
5 |
6 | __all__ = ["IndexSymmetrisation", "IndexSpinSymmetrisation",
7 | "davidson", "EigenSolverStateBase"]
8 |
--------------------------------------------------------------------------------
/adcc/solver/common.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import numpy as np
24 |
25 |
26 | def select_eigenpairs(eigenvalues, n_ep, which):
27 | """
28 | Return a numpy `bool` mask selecting the `n_ep` eigenpairs of the `which`
29 | criterion. It is assumed that the `eigenvalues` are sorted algebraically
30 | from the smallest to the largest.
31 | """
32 | mask = np.zeros(len(eigenvalues), dtype=bool)
33 | if which == "LA": # Largest algebraic
34 | mask[-n_ep:] = True
35 | elif which == "SA": # Smallest algebraic
36 | mask[:n_ep] = True
37 | elif which == "LM": # Largest magnitude
38 | sorti = np.argsort(np.abs(eigenvalues))[-n_ep:]
39 | mask[sorti] = True
40 | elif which == "SM": # Smallest magnitude
41 | sorti = np.argsort(np.abs(eigenvalues))[:n_ep]
42 | mask[sorti] = True
43 | else:
44 | raise ValueError("For now only the values 'LM', 'LA', 'SM' and 'SA' "
45 | "are understood for 'which'.")
46 | return mask.nonzero()[0]
47 |
--------------------------------------------------------------------------------
/adcc/tests/AdcMatrix_dense_export_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import pytest
24 | import numpy as np
25 | from numpy.testing import assert_allclose
26 |
27 | import adcc
28 |
29 | from .testdata_cache import testdata_cache
30 | from . import testcases
31 |
32 |
33 | h2o = testcases.get_by_filename("h2o_sto3g").pop()
34 | cases = ["gen", "cvs"]
35 | assert all(c in h2o.cases for c in cases)
36 | methods = ["adc1", "adc2", "adc2x", "adc3"]
37 |
38 |
39 | @pytest.mark.parametrize("case", cases)
40 | @pytest.mark.parametrize("method", methods)
41 | class TestAdcMatrixDenseExport:
42 | # TODO Testing this for CN is a bit tricky, because
43 | # the dense basis we employ is not yet spin-adapted
44 | # and allows e.g. simultaneous α->α and α->β components to mix
45 | # A closer investigation is needed here
46 | def test_h2o(self, case: str, method: str):
47 | if "cvs" in case and "cvs" not in method:
48 | method = f"cvs-{method}"
49 | method: adcc.AdcMethod = adcc.AdcMethod(method)
50 | n_states = 7
51 | if method.level == 1: # only few states available
52 | n_states = 5
53 | if method.is_core_valence_separated:
54 | n_states = 1 if "fv" in case else 2
55 | elif "fc" in case and "fv" in case:
56 | n_states = 4
57 | elif method.level == 2 and method.is_core_valence_separated:
58 | # there seems to be a difference for higher cvs-adc2 states...
59 | n_states = 3
60 |
61 | conv_tol = 1e-8
62 |
63 | refstate = testdata_cache.refstate(h2o, case=case)
64 | matrix = adcc.AdcMatrix(method, refstate)
65 | state = adcc.run_adc(
66 | matrix, method=method, conv_tol=conv_tol, n_states=n_states,
67 | max_subspace=7 * n_states
68 | )
69 |
70 | dense = matrix.to_ndarray()
71 | assert_allclose(dense, dense.T, rtol=1e-10, atol=1e-12)
72 |
73 | spectrum = np.linalg.eigvalsh(dense)
74 | rounded = np.unique(np.round(spectrum, 10))[:n_states]
75 | assert_allclose(state.excitation_energy, rounded, atol=10 * conv_tol)
76 |
--------------------------------------------------------------------------------
/adcc/tests/AmplitudeVector_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2021 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import pytest
24 | import unittest
25 | import numpy as np
26 |
27 | import adcc
28 | from .testdata_cache import testdata_cache
29 |
30 |
31 | class TestAmplitudeVector(unittest.TestCase):
32 | def test_functionality(self):
33 | ground_state = adcc.LazyMp(testdata_cache.refstate("h2o_sto3g", case="gen"))
34 | matrix = adcc.AdcMatrix("adc2", ground_state)
35 | vectors = [adcc.guess_zero(matrix) for _ in range(2)]
36 | for vec in vectors:
37 | vec.set_random()
38 | v, w = vectors
39 | with pytest.raises(AttributeError):
40 | v.pph
41 | with pytest.raises(AttributeError):
42 | v.pph = w.ph
43 | # setattr with expression
44 | z = adcc.zeros_like(v)
45 | z.ph = v.ph + w.ph
46 | z -= w
47 | np.testing.assert_allclose(
48 | v.ph.to_ndarray(), z.ph.to_ndarray()
49 | )
50 |
--------------------------------------------------------------------------------
/adcc/tests/HartreeFockProvider_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import adcc
24 | import unittest
25 | from pytest import approx
26 |
27 | from adcc import ExcitedStates
28 | from adcc.DataHfProvider import DataHfProvider
29 |
30 | from .testdata_cache import testdata_cache
31 |
32 |
33 | class TestHartreeFockProvider(unittest.TestCase):
34 | def base_test(self, system: str, **args):
35 | hf = DataHfProvider(testdata_cache._load_hfdata(system))
36 | refdata = testdata_cache.adcman_data(
37 | system, method="adc2", case="gen"
38 | )["singlet"]
39 |
40 | res = adcc.adc2(hf, n_singlets=9, **args)
41 | assert isinstance(res, ExcitedStates)
42 | assert res.converged
43 |
44 | ref = refdata["eigenvalues"]
45 | assert res.excitation_energy[:len(ref)] == approx(ref)
46 |
47 | refdata = testdata_cache.adcc_data(
48 | system, method="adc2", case="gen"
49 | )["singlet"]
50 | ref = refdata["eigenvalues"]
51 | assert res.excitation_energy[:len(ref)] == approx(ref)
52 |
53 | def test_h2o(self):
54 | self.base_test("h2o_sto3g")
55 |
--------------------------------------------------------------------------------
/adcc/tests/ReferenceState_backends_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import pytest
24 |
25 | import adcc
26 |
27 | from . import testcases
28 | from .testdata_cache import testdata_cache
29 | from .backends.testing import cached_backend_hf
30 | from .ReferenceState_refdata_test import compare_refstate_with_reference
31 |
32 |
33 | test_cases = testcases.get_by_filename(
34 | "h2o_sto3g", "h2o_def2tzvp", "cn_sto3g", "cn_ccpvdz", "ch2nh2_sto3g"
35 | )
36 | cases = [(case.file_name, c) for case in test_cases for c in case.cases]
37 | backends = [b for b in adcc.backends.available() if b != "molsturm"]
38 |
39 |
40 | @pytest.mark.parametrize("system,case", cases)
41 | @pytest.mark.parametrize("backend", backends)
42 | def test_backends_import_reference_data(system: str, case: str, backend: str):
43 | system: testcases.TestCase = testcases.get_by_filename(system).pop()
44 |
45 | if backend == "veloxchem":
46 | if system.basis == "def2-tzvp" and system.name == "h2o":
47 | pytest.skip("VeloxChem does not support f-functions.")
48 |
49 | compare_eri = "abs"
50 | if system.name == "cn":
51 | compare_eri = "off"
52 |
53 | conv_tol = 1e-11
54 | if backend == "veloxchem":
55 | conv_tol = 1e-7
56 | data = testdata_cache._load_hfdata(system) # is also cached
57 | reference = testdata_cache.hfimport(system, case=case)
58 | # perform a new scf calculation with the backend
59 | scfres = cached_backend_hf(backend=backend, system=system, conv_tol=conv_tol)
60 | compare_refstate_with_reference(
61 | system=system, case=case, data=data, reference=reference, scfres=scfres,
62 | compare_orbcoeff=False, compare_eri=compare_eri
63 | )
64 |
--------------------------------------------------------------------------------
/adcc/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/adcc/tests/__init__.py
--------------------------------------------------------------------------------
/adcc/tests/adc_pp/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/adcc/tests/adc_pp/__init__.py
--------------------------------------------------------------------------------
/adcc/tests/backends/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/adcc/tests/backends/__init__.py
--------------------------------------------------------------------------------
/adcc/tests/conftest.py:
--------------------------------------------------------------------------------
1 | from . import testcases
2 |
3 | from pathlib import Path
4 | import os
5 | import pytest
6 | import subprocess
7 |
8 |
9 | _testdata_dirname = "data"
10 |
11 |
12 | def update_testdata(session):
13 | testdata_dir = Path(__file__).resolve().parent / _testdata_dirname
14 | cmd = [f"{testdata_dir}/update_testdata.sh"]
15 | if session.config.option.mode == "full":
16 | cmd.append("--full")
17 | subprocess.check_call(cmd)
18 |
19 |
20 | #
21 | # Pytest Hooks
22 | #
23 |
24 | def pytest_addoption(parser: pytest.Parser) -> None:
25 | # could also use pytest.mark.fast/slow
26 | # -> pytest -m fast/slow to only run the marked tests
27 | parser.addoption(
28 | "--mode", default="fast", choices=["fast", "full"],
29 | help="Mode for testing (fast or full)"
30 | )
31 | parser.addoption(
32 | "--skip-update", default=False, action="store_true",
33 | help="Skip updating testdata"
34 | )
35 | parser.addoption(
36 | "--allocator", default="standard", choices=["standard", "libxm"],
37 | help="Allocator to use for the tests"
38 | )
39 |
40 |
41 | def pytest_collection_modifyitems(config: pytest.Config,
42 | items: list[pytest.Item]) -> None:
43 | # Called after collection has been performed.
44 | # May filter or re-order the items in-place.
45 | # -> Skip all "slow" tests if not running in full mode
46 | if config.getoption("mode") == "fast":
47 | slow_cases = [case.file_name for case in testcases.available
48 | if case.only_full_mode]
49 | skip_slow = pytest.mark.skip(reason="need '--mode full' option to run.")
50 | for item in items:
51 | if any(name in kw for kw in item.keywords for name in slow_cases):
52 | item.add_marker(skip_slow)
53 |
54 |
55 | def pytest_collection(session):
56 | # Perform the collection phase for the given session.
57 | if not session.config.option.skip_update:
58 | update_testdata(session)
59 |
60 |
61 | def pytest_runtestloop(session):
62 | # Perform the main runtest loop (after collection finished).
63 | if os.environ.get("CI", "false") == "true":
64 | import adcc
65 |
66 | # use more moderate thread setup in continuous integration environment
67 | print("Detected continuous integration session")
68 | adcc.set_n_threads(2)
69 | if session.config.option.allocator != "standard":
70 | import adcc
71 |
72 | allocator = session.config.option.allocator
73 | adcc.memory_pool.initialise(allocator=allocator)
74 | print(f"Using allocator: {allocator}")
75 |
--------------------------------------------------------------------------------
/adcc/tests/data/.gitignore:
--------------------------------------------------------------------------------
1 | *.hdf5
2 |
--------------------------------------------------------------------------------
/adcc/tests/data/make_shasums.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if ! which sha256sum &> /dev/null; then
4 | echo "sha256sum not installed" >&2
5 | exit 1
6 | fi
7 |
8 | # move in the folder of the script
9 | SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
10 | cd "$SCRIPT_DIR"
11 |
12 | # Take the filename as positional argument
13 | # or default to SHA256SUMS
14 | SHAFILE=${1:-SHA256SUMS}
15 | if [ -f "$SHAFILE" ] && [ -s "$SHAFILE" ]; then
16 | echo "The file $SHAFILE already exists" >&2
17 | exit 1
18 | fi
19 |
20 | # compute the sha256sums for all hdf5 files in the workdir
21 | for file in *.hdf5; do
22 | [ -f "$file" ] || break
23 | sha256sum "$file" >> "$SHAFILE"
24 | done
25 |
--------------------------------------------------------------------------------
/adcc/tests/data/psi4_data.json:
--------------------------------------------------------------------------------
1 | {
2 | "formaldehyde_sto3g_pcm_adc1": {
3 | "basis": "sto-3g",
4 | "method": "adc1",
5 | "molecule": "formaldehyde",
6 | "energy_scf": -112.35458302984634,
7 | "lr_excitation_energy": [
8 | 0.164670987,
9 | 0.360903879,
10 | 0.465492571,
11 | 0.50874055,
12 | 0.693857844
13 | ],
14 | "lr_osc_strength": [
15 | 0.0,
16 | 0.01075,
17 | 0.34344,
18 | 0.0,
19 | 0.35858
20 | ],
21 | "ptlr_adcc_excitation_energy": [
22 | 0.164676366,
23 | 0.360930626,
24 | 0.467575499,
25 | 0.508742077,
26 | 0.694474733
27 | ]
28 | },
29 | "formaldehyde_ccpvdz_pcm_adc1": {
30 | "basis": "cc-pvdz",
31 | "method": "adc1",
32 | "molecule": "formaldehyde",
33 | "energy_scf": -113.88427067069401,
34 | "lr_excitation_energy": [
35 | 0.178995043,
36 | 0.38176984,
37 | 0.388019451,
38 | 0.392159876,
39 | 0.435439339
40 | ],
41 | "lr_osc_strength": [
42 | 0.0,
43 | 7e-05,
44 | 0.24871,
45 | 0.23489,
46 | 0.0
47 | ],
48 | "ptlr_adcc_excitation_energy": [
49 | 0.179023803,
50 | 0.381851507,
51 | 0.389584048,
52 | 0.392594038,
53 | 0.435463212
54 | ]
55 | },
56 | "psi4_version": "1.9.1"
57 | }
--------------------------------------------------------------------------------
/adcc/tests/data/pyscf_data.json:
--------------------------------------------------------------------------------
1 | {
2 | "formaldehyde_sto3g_pcm_adc1": {
3 | "basis": "sto-3g",
4 | "method": "adc1",
5 | "molecule": "formaldehyde",
6 | "energy_scf": -112.3541947817103,
7 | "lr_excitation_energy": [
8 | 0.164262545,
9 | 0.3602197,
10 | 0.464989894,
11 | 0.509341976,
12 | 0.693093121
13 | ],
14 | "lr_osc_strength": [
15 | 0.0,
16 | 0.01097,
17 | 0.3439,
18 | 0.0,
19 | 0.35916
20 | ],
21 | "ptlr_adcc_excitation_energy": [
22 | 0.164269049,
23 | 0.360249357,
24 | 0.46720581,
25 | 0.509343636,
26 | 0.693731711
27 | ]
28 | },
29 | "formaldehyde_ccpvdz_pcm_adc1": {
30 | "basis": "cc-pvdz",
31 | "method": "adc1",
32 | "molecule": "formaldehyde",
33 | "energy_scf": -113.88314970984436,
34 | "lr_excitation_energy": [
35 | 0.177949797,
36 | 0.380254888,
37 | 0.386524773,
38 | 0.390510552,
39 | 0.435870124
40 | ],
41 | "lr_osc_strength": [
42 | 0.0,
43 | 0.00013,
44 | 0.2486,
45 | 0.23762,
46 | 0.0
47 | ],
48 | "ptlr_adcc_excitation_energy": [
49 | 0.177984524,
50 | 0.380346664,
51 | 0.388200903,
52 | 0.390984688,
53 | 0.435898056
54 | ]
55 | },
56 | "pyscf_version": "2.8.0"
57 | }
--------------------------------------------------------------------------------
/adcc/tests/data/tmole_data.json:
--------------------------------------------------------------------------------
1 | {
2 | "formaldehyde_sto3g_pe_adc2": {
3 | "basis": "sto-3g",
4 | "method": "adc2",
5 | "molecule": "formaldehyde",
6 | "energy_scf": -112.36904349555,
7 | "energy_mp2": -112.4804685653,
8 | "excitation_energy": [
9 | 0.1733632144,
10 | 0.3815240343,
11 | 0.5097618218,
12 | 0.5189443358,
13 | 0.5670575778
14 | ]
15 | },
16 | "formaldehyde_ccpvdz_pe_adc2": {
17 | "basis": "cc-pvdz",
18 | "method": "adc2",
19 | "molecule": "formaldehyde",
20 | "energy_scf": -113.89976872224,
21 | "energy_mp2": -114.2156673890,
22 | "excitation_energy": [
23 | 0.1596037963,
24 | 0.3123344811,
25 | 0.3621306427,
26 | 0.3795572252,
27 | 0.4089162982
28 | ]
29 | }
30 | }
--------------------------------------------------------------------------------
/adcc/tests/generators/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/adcc/tests/generators/__init__.py
--------------------------------------------------------------------------------
/adcc/tests/generators/generate_hfimport.py:
--------------------------------------------------------------------------------
1 | from adcc.tests.testdata_cache import testdata_cache
2 | from adcc.tests import testcases
3 |
4 | import adcc
5 | from adcc.hdf5io import emplace_dict
6 |
7 | from pathlib import Path
8 | import numpy as np
9 | import h5py
10 | import itertools
11 |
12 |
13 | _testdata_dirname = "data"
14 |
15 |
16 | def dump_imported(test_case: testcases.TestCase):
17 | hdf5_file = Path(__file__).resolve().parent.parent / _testdata_dirname
18 | hdf5_file /= test_case.hfimport_file_name
19 | hdf5_file = h5py.File(hdf5_file, "a") # Read/write if exists, create otherwise
20 | # go through the reference cases
21 | for case in test_case.cases:
22 | if case in hdf5_file:
23 | continue
24 | # build the reference state for the given reference case
25 | print(f"Generating hfimport data for {case} {test_case.file_name}.")
26 | refstate = testdata_cache.refstate(test_case, case)
27 | # extract the relevant data to dictionary
28 | data = collect_data(refstate)
29 | # and write in the hdf5 file
30 | case_group = hdf5_file.create_group(case)
31 | emplace_dict(data, case_group, compression="gzip")
32 | case_group.attrs["adcc_version"] = adcc.__version__
33 |
34 |
35 | def collect_data(refstate: adcc.ReferenceState) -> dict:
36 | subspaces = refstate.mospaces.subspaces
37 |
38 | # dump the subspaces
39 | ret = {"subspaces": np.array(subspaces, dtype="S")} # dtype S: char bytes
40 | # and the orbital energies + orbital coefficients
41 | for space in subspaces:
42 | ret[f"orbital_energies/{space}"] = (
43 | refstate.orbital_energies(space).to_ndarray()
44 | )
45 | ret[f"orbital_coefficients/{space}b"] = (
46 | refstate.orbital_coefficients(f"{space}b").to_ndarray()
47 | )
48 | # dump the fock matrix
49 | canonical_pairs = []
50 | for space1, space2 in itertools.combinations_with_replacement(subspaces, 2):
51 | canonical_pairs.append(space1 + space2)
52 | ret[f"fock/{space1}{space2}"] = refstate.fock(space1 + space2).to_ndarray()
53 | # dump the eri
54 | for bra, ket in itertools.combinations_with_replacement(canonical_pairs, 2):
55 | ret[f"eri/{bra}{ket}"] = refstate.eri(bra + ket).to_ndarray()
56 | return ret
57 |
58 |
59 | def main():
60 | test_cases = testcases.get_by_filename(
61 | "h2o_sto3g", "h2o_def2tzvp", "cn_sto3g", "cn_ccpvdz", "ch2nh2_sto3g"
62 | )
63 | for tcase in test_cases:
64 | dump_imported(tcase)
65 |
66 |
67 | if __name__ == "__main__":
68 | main()
69 |
--------------------------------------------------------------------------------
/adcc/tests/hardcoded_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2020 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import adcc
24 | import unittest
25 | import numpy as np
26 |
27 | from .testdata_cache import testdata_cache
28 |
29 |
30 | class TestHardCodedCisResults(unittest.TestCase):
31 | def test_methox_sto3g_singlet(self):
32 | vlx_result = {
33 | 'excitation_energies': np.array(
34 | [0.37722854, 0.42890135, 0.50227467, 0.52006496,
35 | 0.55583901, 0.59846662]
36 | ),
37 | 'rotatory_strengths': np.array(
38 | [-0.00170464, 0.00191897, 0.02054426, -0.00429405,
39 | 0.04966345, 0.03289564]
40 | ),
41 | 'oscillator_strengths': np.array(
42 | [1.93724710e-04, 1.29809765e-03, 3.28195555e-01,
43 | 2.55565534e-02, 3.10309645e-01, 1.43808081e-02]
44 | )
45 | }
46 | hf = testdata_cache._load_hfdata("r2methyloxirane_sto3g")
47 | state = adcc.cis(hf, n_singlets=6, conv_tol=1e-8)
48 | np.testing.assert_allclose(vlx_result['excitation_energies'],
49 | state.excitation_energy, atol=1e-6)
50 | np.testing.assert_allclose(vlx_result['rotatory_strengths'],
51 | state.rotatory_strength, atol=1e-4)
52 | np.testing.assert_allclose(vlx_result['oscillator_strengths'],
53 | state.oscillator_strength, atol=1e-4)
54 |
--------------------------------------------------------------------------------
/adcc/tests/misc_test.py:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | from adcc.misc import cached_member_function
4 |
5 |
6 | class SomeClass:
7 | def uncached(self, x=0, y=1):
8 | return (x, y)
9 |
10 | @cached_member_function
11 | def cached(self, x=0, y=1):
12 | return (x, y)
13 |
14 |
15 | class TestCachedMemberFunction(unittest.TestCase):
16 | def test_cache(self):
17 | instance = SomeClass()
18 | assert instance.uncached() is not instance.uncached()
19 | res = instance.cached(0, 1)
20 | assert res is instance.cached(0, 1)
21 | assert res is instance.cached(0)
22 | assert res is instance.cached()
23 | assert res is instance.cached(x=0)
24 | assert res is instance.cached(y=1)
25 | assert res is instance.cached(y=1, x=0)
26 |
27 | def test_wrappable(self):
28 | def kwargs_only(self, *, kwarg):
29 | pass
30 |
31 | def kwargs(self, **kwargs):
32 | pass
33 |
34 | def positional_only(self, /, arg):
35 | pass
36 |
37 | def args(self, *args):
38 | pass
39 |
40 | with self.assertRaises(ValueError):
41 | cached_member_function(kwargs_only)
42 | with self.assertRaises(ValueError):
43 | cached_member_function(kwargs)
44 | cached_member_function(positional_only)
45 | cached_member_function(args)
46 |
--------------------------------------------------------------------------------
/adcc/tests/solver/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/adcc/tests/solver/__init__.py
--------------------------------------------------------------------------------
/adcc/tests/solver/power_method_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import pytest
24 | import numpy as np
25 | from numpy.testing import assert_allclose
26 | from scipy.sparse.linalg import aslinearoperator
27 |
28 | from adcc.solver.power_method import default_print, power_method
29 |
30 |
31 | sizes = ["0004", "0050", "0200", "1000"]
32 |
33 |
34 | @pytest.mark.parametrize("size", sizes)
35 | class TestPowerMethod:
36 | def test_random_matrix(self, size: str):
37 | np.random.seed(42)
38 | size = int(size)
39 | conv_tol = 1e-10
40 | ev = np.random.randn(size)
41 | ev[0] = abs(ev[0]) + 5
42 |
43 | start = np.random.randn(len(ev))
44 | start[0] += 0.001
45 | res = power_method(aslinearoperator(np.diag(ev)), start,
46 | conv_tol=conv_tol, callback=default_print,
47 | explicit_symmetrisation=None,
48 | max_iter=100)
49 |
50 | ones = np.zeros(size)
51 | ones[0] = 1 * np.sign(res.eigenvectors[0][0])
52 | extrafac = 1
53 | if size > 100:
54 | extrafac = 3
55 | assert_allclose(res.eigenvectors[0], ones, atol=conv_tol * 10 * extrafac)
56 | assert pytest.approx(res.eigenvalues[0]) == ev[0]
57 |
--------------------------------------------------------------------------------
/adcc/visualisation/ExcitationSpectrum.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | from .Spectrum import Spectrum
24 |
25 |
26 | class ExcitationSpectrum(Spectrum):
27 | def __init__(self, energy, intensity):
28 | """Construct an ExcitationSpectrum object
29 |
30 | Parameters
31 | ----------
32 | energy
33 | Energies for plotting the spectrum
34 | intensity
35 | Intensities for plotting the spectrum
36 | """
37 | super().__init__(energy, intensity)
38 | self.xlabel = "Energy"
39 | self.ylabel = "Intensity"
40 |
--------------------------------------------------------------------------------
/adcc/visualisation/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | from .ExcitationSpectrum import ExcitationSpectrum
24 |
25 | __all__ = ["ExcitationSpectrum"]
26 |
--------------------------------------------------------------------------------
/adcc/visualisation/shapefctns.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | ## ---------------------------------------------------------------------
4 | ##
5 | ## Copyright (C) 2019 by the adcc authors
6 | ##
7 | ## This file is part of adcc.
8 | ##
9 | ## adcc is free software: you can redistribute it and/or modify
10 | ## it under the terms of the GNU General Public License as published
11 | ## by the Free Software Foundation, either version 3 of the License, or
12 | ## (at your option) any later version.
13 | ##
14 | ## adcc is distributed in the hope that it will be useful,
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ## GNU General Public License for more details.
18 | ##
19 | ## You should have received a copy of the GNU General Public License
20 | ## along with adcc. If not, see .
21 | ##
22 | ## ---------------------------------------------------------------------
23 | import numpy as np
24 |
25 |
26 | def gaussian(x, x0, stddev):
27 | fac = 1 / np.sqrt(2 * np.pi * stddev**2)
28 | return fac * np.exp(-(x - x0)**2 / (2 * stddev**2))
29 |
30 |
31 | def lorentzian(x, x0, gamma):
32 | return gamma / ((x - x0)**2 + gamma**2) / np.pi
33 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
--------------------------------------------------------------------------------
/conda/environment.yml:
--------------------------------------------------------------------------------
1 | name: adcc-dev
2 | channels:
3 | - conda-forge
4 | - nodefaults
5 | dependencies:
6 | # Build
7 | - python
8 | - gcc_linux-64
9 | - gxx_linux-64
10 | - libtensorlight >=3.0.1
11 | - pybind11 >=2.6
12 | - pip
13 | # Run
14 | - numpy >=1.14
15 | - scipy >=1.2
16 | - tqdm >=4.30
17 | - h5py >=2.9
18 | - opt_einsum >=3.0
19 | # Tests
20 | - pandas >=0.25.0
21 | - cppe >=0.3.1
22 | - pytest
23 | - pytest-cov
24 | - lcov
25 | - pip:
26 | - pyscf
27 |
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | api/
2 |
--------------------------------------------------------------------------------
/docs/Doxyfile:
--------------------------------------------------------------------------------
1 | PROJECT_NAME = libadcc
2 | PROJECT_NUMBER =
3 | PROJECT_BRIEF = "Compiled component to adcc"
4 |
5 | INPUT = ../libadcc
6 | RECURSIVE = YES
7 | OUTPUT_DIRECTORY = ../build/libadcc_docs
8 | EXCLUDE_PATTERNS = *.cc */tests/* */pyiface/* *.py
9 |
10 | GENERATE_LATEX = NO
11 | GENERATE_HTML = NO
12 | GENERATE_XML = YES
13 |
14 | LOOKUP_CACHE_SIZE = 3
15 |
--------------------------------------------------------------------------------
/docs/about.rst:
--------------------------------------------------------------------------------
1 | :github_url: https://github.com/adc-connect/adcc/blob/master/docs/about.rst
2 |
3 | About this project
4 | ==================
5 |
6 | The adcc project was initiated at Heidelberg University
7 | from the frustration of the difficulties encountered when
8 | starting ADC calculations from unusual
9 | SCF references (in this case from the `molsturm `_ code).
10 | In the initial phase of development adcc was heavily
11 | inspired by the `adcman `_ package
12 | by Michael Wormit *et. al.*.
13 | By the time of the first release in late 2019 the structure of adcc
14 | has been completely rewritten and polished
15 | and finally in late 2020 the code became fully open-source.
16 |
17 | In its current form adcc features a strong focus on flexibility
18 | for both developing novel ADC methods
19 | and performing sophisticated analysis on top of obtained computational results.
20 | Standard workflows like plotting spectra or visualising obtained results
21 | are simple and often only take a single command,
22 | but still provide access to underlying low-level objects to make
23 | customisation possible.
24 | As a result the project is accessible to novices to the field,
25 | but still offers a low barrier to start developing more complex
26 | simulation procedures, where this might be needed.
27 | As numerous :ref:`adcc-related publications` prove
28 | this philosophy has already enabled key advances
29 | and successfully pushed the state of the art in computational spectroscopy methods.
30 | A more detailed overview of adcc and its features can be found in :cite:`adcc`.
31 |
32 |
33 | Citation
34 | --------
35 | We kindly ask all users of adcc, who find the package useful for their
36 | research to cite the adcc paper :cite:`adcc` in their publications.
37 |
38 |
39 | .. _contact-us:
40 |
41 | Contact us
42 | ----------
43 |
44 | You found a bug? Something is not working?
45 | You have a great idea about a possible feature for adcc?
46 | The primary place to discuss such issues about adcc is
47 | `our issue page on github `_.
48 | Alternatively you can also reach us by mail (``developers@adc-connect.org``).
49 |
--------------------------------------------------------------------------------
/docs/benchmarks.rst:
--------------------------------------------------------------------------------
1 | :github_url: https://github.com/adc-connect/adcc/blob/master/docs/benchmarks.rst
2 |
3 | .. _benchmarks:
4 |
5 | Benchmarks and timings
6 | ======================
7 |
8 | This page provides an overview of the time and memory requirements
9 | of running ADC calculations based on a few benchmark cases.
10 |
11 | The results have been generated with our automated
12 | benchmarking suite `adcc-bench `_,
13 | which is based on `airspeed-velocity `_.
14 | The benchmarks of adcc-bench are run periodically on the master branch
15 | of adcc in order to track performance of adcc across releases.
16 |
17 | .. include:: benchmarks/commit.rst
18 |
19 | Cluster benchmarks on Intel(R) Xeon(R) E5-2643
20 | ----------------------------------------------
21 |
22 | These benchmarks have been run on a node with two
23 | Intel(R) Xeon(R) E5-2643 CPUs @ 3.30GHz.
24 |
25 | Noradrenaline
26 | ~~~~~~~~~~~~~
27 |
28 | .. include:: benchmarks/Noradrenaline.rst
29 |
30 | *p*-Nitroaniline
31 | ~~~~~~~~~~~~~~~~
32 |
33 | .. include:: benchmarks/ParaNitroAniline.rst
34 |
35 | Phosphine core excited states
36 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 |
38 | .. include:: benchmarks/PhosphineCvs.rst
39 |
40 | Methylammonium radical
41 | ~~~~~~~~~~~~~~~~~~~~~~
42 |
43 | .. include:: benchmarks/MethylammoniumRadical.rst
44 |
45 | Water
46 | ~~~~~
47 |
48 | .. include:: benchmarks/WaterExpensive.rst
49 |
--------------------------------------------------------------------------------
/docs/benchmarks/MethylammoniumRadical.rst:
--------------------------------------------------------------------------------
1 | - **Basis set:** cc-pVTZ (116 functions)
2 | - **Reference:** UHF
3 | - **Convergence tolerance:** 1e-06
4 | - **Number of states:** 10 (energies and oscillator strength)
5 | - **Threads:** 4
6 |
7 | ========= ============= ====================
8 | method time (s) peak memory (MiB)
9 | ========= ============= ====================
10 | adc1 8 1440
11 | adc2 139 8890
12 | adc2x 520 8309
13 | adc3 558 9693
14 | ========= ============= ====================
--------------------------------------------------------------------------------
/docs/benchmarks/Noradrenaline.rst:
--------------------------------------------------------------------------------
1 | - **Basis set:** 6-311++G** (341 functions)
2 | - **Reference:** RHF
3 | - **Convergence tolerance:** 1e-06
4 | - **Number of states:** 5 (energies and oscillator strength)
5 | - **Threads:** 16
6 |
7 | ========= ============= ====================
8 | method time (s) peak memory (MiB)
9 | ========= ============= ====================
10 | adc1 140 45515
11 | adc2 6612 258251
12 | ========= ============= ====================
--------------------------------------------------------------------------------
/docs/benchmarks/ParaNitroAniline.rst:
--------------------------------------------------------------------------------
1 | - **Basis set:** cc-pVDZ (170 functions)
2 | - **Reference:** RHF
3 | - **Convergence tolerance:** 1e-06
4 | - **Number of states:** 7 (energies and oscillator strength)
5 | - **Threads:** 16
6 |
7 | ========= ============= ====================
8 | method time (s) peak memory (MiB)
9 | ========= ============= ====================
10 | adc1 25 4404
11 | adc2 670 35247
12 | ========= ============= ====================
--------------------------------------------------------------------------------
/docs/benchmarks/PhosphineCvs.rst:
--------------------------------------------------------------------------------
1 | - **Basis set:** 6-311++G** (51 functions)
2 | - **Reference:** RHF
3 | - **Convergence tolerance:** 1e-06
4 | - **Number of states:** 10 (energies and oscillator strength)
5 | - **Threads:** 4
6 |
7 | ========= ============= ====================
8 | method time (s) peak memory (MiB)
9 | ========= ============= ====================
10 | cvs_adc1 1 152
11 | cvs_adc2 13 237
12 | cvs_adc2x 23 324
13 | cvs_adc3 39 335
14 | ========= ============= ====================
--------------------------------------------------------------------------------
/docs/benchmarks/WaterExpensive.rst:
--------------------------------------------------------------------------------
1 | - **Basis set:** cc-pVQZ (115 functions)
2 | - **Reference:** RHF
3 | - **Convergence tolerance:** 1e-06
4 | - **Number of states:** 10 (energies and oscillator strength)
5 | - **Threads:** 8
6 |
7 | ========= ============= ====================
8 | method time (s) peak memory (MiB)
9 | ========= ============= ====================
10 | adc2 26 3158
11 | adc2x 120 3425
12 | adc3 135 4787
13 | ========= ============= ====================
--------------------------------------------------------------------------------
/docs/benchmarks/commit.rst:
--------------------------------------------------------------------------------
1 | This summary only shows a few key results, which have been generated using commit **9c7bba83** from the `adcc repository `_. The full results in interactive form is accessible on https://adc-connect.github.io/adcc-bench.
--------------------------------------------------------------------------------
/docs/hostprograms.rst:
--------------------------------------------------------------------------------
1 | :github_url: https://github.com/adc-connect/adcc/blob/master/docs/hostprograms.rst
2 |
3 | .. _hostprograms:
4 |
5 | Connecting host programs to adcc
6 | ================================
7 |
8 | Documentation for host programs and how to talk to adcc
9 |
10 | Python dictionary or HDF5 file
11 | ------------------------------
12 |
13 | .. autoclass:: adcc.DataHfProvider
14 | :members: __init__
15 |
16 |
17 | Host-program specific interface
18 | -------------------------------
19 |
20 | For implementing a host-program specific interface
21 | to adcc, taking advantage of all features of the host program,
22 | a derived class of the :class:`adcc.HartreeFockProvider` has to be implemented.
23 | The interface for this is:
24 |
25 | .. autoclass:: adcc.HartreeFockProvider
26 | :members:
27 |
28 | Examples in the adcc source code for these interface are
29 | located in the
30 | `adcc/backend folder `_.
31 | For example `pyscf.py `_
32 | or `psi4.py `_.
33 |
34 | .. note::
35 | TODO Explain the OperatorIntegralProvider and its mechanism.
36 |
37 | C++ interface
38 | -------------
39 | For directly passing data to *libadcc* on the C++ level,
40 | the following interface needs to be implemented:
41 |
42 | .. doxygenclass:: libadcc::HartreeFockSolution_i
43 | :members:
44 |
--------------------------------------------------------------------------------
/docs/images/ecd_methyloxirane.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/images/ecd_methyloxirane.png
--------------------------------------------------------------------------------
/docs/images/generate_plot_spectrum_water.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | from pyscf import gto, scf
4 | from matplotlib import pyplot as plt
5 |
6 | import adcc
7 |
8 | # pyscf-H2O Hartree-Fock calculation
9 | mol = gto.M(
10 | atom='O 0 0 0;'
11 | 'H 0 0 1.795239827225189;'
12 | 'H 1.693194615993441 0 -0.599043184453037',
13 | basis='cc-pvtz',
14 | unit="Bohr"
15 | )
16 | scfres = scf.RHF(mol)
17 | scfres.conv_tol = 1e-13
18 | scfres.kernel()
19 |
20 |
21 | plt.figure(figsize=(7, 5))
22 | state = adcc.adc2(scfres, n_singlets=10)
23 | state.plot_spectrum()
24 |
25 | plt.savefig("plot_spectrum_water.png", bbox="tight")
26 | plt.close()
27 |
--------------------------------------------------------------------------------
/docs/images/matrix/.gitignore:
--------------------------------------------------------------------------------
1 | /water_*.hdf5
2 |
--------------------------------------------------------------------------------
/docs/images/matrix/adc_matrix_schematic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/images/matrix/adc_matrix_schematic.png
--------------------------------------------------------------------------------
/docs/images/matrix/matrix_water_adc2_sto3g.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/images/matrix/matrix_water_adc2_sto3g.png
--------------------------------------------------------------------------------
/docs/images/matrix/matrix_water_adc3_sto3g.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/images/matrix/matrix_water_adc3_sto3g.png
--------------------------------------------------------------------------------
/docs/images/plot_spectrum_water.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/images/plot_spectrum_water.png
--------------------------------------------------------------------------------
/docs/images/setup_environment.sh:
--------------------------------------------------------------------------------
1 | THISDIR=$(dirname "${BASH_SOURCE[0]}")
2 | export PYTHONPATH="$PYTHONPATH:$THISDIR/../.."
3 | unset THISDIR
4 |
--------------------------------------------------------------------------------
/docs/logo/.gitignore:
--------------------------------------------------------------------------------
1 | *.xcf
2 |
--------------------------------------------------------------------------------
/docs/logo/logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/logo/logo.pdf
--------------------------------------------------------------------------------
/docs/logo/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/docs/logo/logo.png
--------------------------------------------------------------------------------
/docs/logo/make_logo.sh:
--------------------------------------------------------------------------------
1 | latex logo.tex
2 | dvips logo.dvi
3 | ps2pdf -dPDFSETTINGS=/prepress -dEmbedAllFonts=true logo.ps
4 | gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -sOutputFile=logo.pdf -f logo.ps
5 | rm logo.dvi logo.ps logo.aux logo.log
6 | convert -density 1000 -depth 10 -quality 95 logo.pdf logo.png
7 |
--------------------------------------------------------------------------------
/docs/pub.bib:
--------------------------------------------------------------------------------
1 | @article{adcc,
2 | title = {{adcc: A versatile toolkit for rapid development of algebraic-diagrammatic construction methods}},
3 | author = {Herbst, Michael F. and Scheurer, Maximilian and Fransson, Thomas and Rehn, Dirk R. and Dreuw, Andreas},
4 | journal = {WIREs Computational Molecular Science},
5 | doi = {10.1002/wcms.1462},
6 | year = {2020},
7 | }
8 | @article{psi4_14,
9 | author = {Smith, Daniel G. A. and Burns, Lori A. and Simmonett, Andrew C. and Parrish, Robert M. and Schieber, Matthew C. and others},
10 | doi = {10.1063/5.0006002},
11 | issue = {18},
12 | journal = {J. Chem. Phys.},
13 | pages = {184108},
14 | title = {Psi4 1.4: Open-source software for high-throughput quantum chemistry},
15 | volume = {152},
16 | year = {2020},
17 | }
18 | @article{complex_excited_polarisabilities,
19 | author = {Scheurer, Maximilian and Fransson, Thomas and Norman,Patrick and Dreuw, Andreas and Rehn, Dirk R. },
20 | title = {Complex excited state polarizabilities in the ADC/ISR framework},
21 | journal = {J. Chem. Phys.},
22 | volume = {153},
23 | number = {7},
24 | pages = {074112},
25 | year = {2020},
26 | doi = {10.1063/5.0012120},
27 | }
28 | @article{cvsrelaxation,
29 | author = {Michael F. Herbst and Thomas Fransson},
30 | title = {{Quantifying the error of the core-valence separation approximation}},
31 | journal = {J. Chem. Phys.},
32 | volume = {153},
33 | number = {5},
34 | pages = {054114},
35 | year = {2020},
36 | doi = {10.1063/5.0013538},
37 | }
38 |
--------------------------------------------------------------------------------
/docs/zpublications.rst:
--------------------------------------------------------------------------------
1 | :github_url: https://github.com/adc-connect/adcc/blob/master/docs/zpublications.rst
2 |
3 | Publications and references
4 | ===========================
5 |
6 | This page holds a collection of publications related to adcc
7 | and lists references and software used in the context of adcc.
8 |
9 | We kindly ask all users of adcc, who find the package useful for their
10 | research to cite the adcc paper :cite:`adcc` and the
11 | `DOI of the adcc code `_
12 | in the version which was used for the calculation.
13 |
14 | .. _publications:
15 |
16 | adcc publications
17 | -----------------
18 |
19 | .. list-table::
20 |
21 | * - **Paper:**
22 | - .. image:: https://img.shields.io/badge/DOI-10.1002/wcms.1462-blue
23 | :target: https://doi.org/10.1002/wcms.1462
24 |
25 | .. image:: https://img.shields.io/badge/hal-preprint-red
26 | :target: https://hal.archives-ouvertes.fr/hal-02319517
27 |
28 | * - **Code:**
29 | - .. image:: https://zenodo.org/badge/215731857.svg
30 | :target: https://zenodo.org/badge/latestdoi/215731857
31 |
32 | .. bibliography:: pub.bib
33 | :all:
34 | :style: unsrtalpha
35 |
36 | Other references
37 | ----------------
38 |
39 | .. bibliography:: ref.bib
40 | :style: alpha
41 |
--------------------------------------------------------------------------------
/environment.yml:
--------------------------------------------------------------------------------
1 | name: adcc37
2 | channels:
3 | - adcc
4 | - psi4/label/dev
5 | - defaults
6 | dependencies:
7 | - python=3.7
8 | - psi4
9 | - adcc
10 |
--------------------------------------------------------------------------------
/examples/.gitignore:
--------------------------------------------------------------------------------
1 | *.pdf
--------------------------------------------------------------------------------
/examples/0_basics/02_Theory.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Numerical methods to solve ADC problems\n",
8 | "\n",
9 | "To be written ...\n",
10 | "\n",
11 | "Will focus mostly on the numerical stuff and what matters for doing the calculations"
12 | ]
13 | }
14 | ],
15 | "metadata": {
16 | "kernelspec": {
17 | "display_name": "Python 3",
18 | "language": "python",
19 | "name": "python3"
20 | },
21 | "language_info": {
22 | "codemirror_mode": {
23 | "name": "ipython",
24 | "version": 3
25 | },
26 | "file_extension": ".py",
27 | "mimetype": "text/x-python",
28 | "name": "python",
29 | "nbconvert_exporter": "python",
30 | "pygments_lexer": "ipython3",
31 | "version": "3.8.2"
32 | }
33 | },
34 | "nbformat": 4,
35 | "nbformat_minor": 4
36 | }
37 |
--------------------------------------------------------------------------------
/examples/0_basics/03_Tweaks.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Tweaking calculations\n",
8 | "\n",
9 | "Will soon feature an explanaition of some adcc tweaks."
10 | ]
11 | }
12 | ],
13 | "metadata": {
14 | "kernelspec": {
15 | "display_name": "Python 3",
16 | "language": "python",
17 | "name": "python3"
18 | },
19 | "language_info": {
20 | "codemirror_mode": {
21 | "name": "ipython",
22 | "version": 3
23 | },
24 | "file_extension": ".py",
25 | "mimetype": "text/x-python",
26 | "name": "python",
27 | "nbconvert_exporter": "python",
28 | "pygments_lexer": "ipython3",
29 | "version": "3.8.3"
30 | }
31 | },
32 | "nbformat": 4,
33 | "nbformat_minor": 4
34 | }
35 |
--------------------------------------------------------------------------------
/examples/0_basics/h2o_sto3g_hfdata.hdf5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adc-connect/adcc/cbc6046ec69f2a823c73635f498c121115df4867/examples/0_basics/h2o_sto3g_hfdata.hdf5
--------------------------------------------------------------------------------
/examples/2_core_excitations/water_core_by_projection.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import adcc.projection
5 |
6 | from pyscf import gto, scf
7 | from adcc.AdcMatrix import AdcMatrixProjected
8 |
9 | # Aim of this script is to compute core excitations of water
10 | # using a projection approach, i.e. where the non-CVS ADC matrix
11 | # is projected into parts of the orbital subspaces to target core
12 | # excitations specifically.
13 |
14 | # Run SCF in pyscf
15 | mol = gto.M(
16 | atom='O 0 0 0;'
17 | 'H 0 0 1.795239827225189;'
18 | 'H 1.693194615993441 0 -0.599043184453037',
19 | basis='cc-pvtz',
20 | unit="Bohr"
21 | )
22 | scfres = scf.RHF(mol)
23 | scfres.conv_tol = 1e-12
24 | scfres.conv_tol_grad = 1e-9
25 | scfres.kernel()
26 | print(adcc.banner())
27 |
28 | # Construct the standard ADC(2)-x matrix and project it, such that
29 | # only cv, ccvv and ocvv excitations are allowed. Choose one orbital (oxygen 1s)
30 | # to make up the core space.
31 | matrix = adcc.AdcMatrix("adc2x", adcc.ReferenceState(scfres))
32 | pmatrix = AdcMatrixProjected(matrix, ["cv", "ccvv", "ocvv"], core_orbitals=1)
33 |
34 | # Run the ADC calculation. Note that doubles guesses are not yet supported in this
35 | # setup and like lead to numerical issues (zero excitations) if selected. So we
36 | # explicitly disable them here.
37 | state_proj = adcc.run_adc(pmatrix, n_singlets=7, conv_tol=1e-8, n_guesses_doubles=0)
38 | print(state_proj.describe())
39 |
40 | # For comparison we also run a standard CVS-ADC(2)-x calculation:
41 | state_cvs = adcc.cvs_adc2x(scfres, n_singlets=7, conv_tol=1e-8, core_orbitals=1)
42 | print(state_cvs.describe())
43 |
44 | # Note that this calculation could also be used as an initial guess:
45 | guesses = adcc.projection.transfer_cvs_to_full(state_cvs, pmatrix)
46 | state_proj2 = adcc.run_adc(pmatrix, n_singlets=7, conv_tol=1e-8, guesses=guesses)
47 |
--------------------------------------------------------------------------------
/examples/environment/psi4_adc2_pna_6w_pol_embed.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import psi4
5 |
6 | from scipy import constants
7 | eV = constants.value("Hartree energy in eV") # Hartree to eV
8 |
9 | # Run SCF in psi4
10 | mol = psi4.geometry("""
11 | C 8.64800 1.07500 -1.71100
12 | C 9.48200 0.43000 -0.80800
13 | C 9.39600 0.75000 0.53800
14 | C 8.48200 1.71200 0.99500
15 | C 7.65300 2.34500 0.05500
16 | C 7.73200 2.03100 -1.29200
17 | H 10.18300 -0.30900 -1.16400
18 | H 10.04400 0.25200 1.24700
19 | H 6.94200 3.08900 0.38900
20 | H 7.09700 2.51500 -2.01800
21 | N 8.40100 2.02500 2.32500
22 | N 8.73400 0.74100 -3.12900
23 | O 7.98000 1.33100 -3.90100
24 | O 9.55600 -0.11000 -3.46600
25 | H 7.74900 2.71100 2.65200
26 | H 8.99100 1.57500 2.99500
27 | symmetry c1
28 | no_reorient
29 | no_com
30 | """)
31 |
32 | psi4.core.set_num_threads(4)
33 | psi4.set_options({'basis': "sto-3g",
34 | 'scf_type': 'pk',
35 | 'pe': 'true',
36 | 'e_convergence': 1e-10,
37 | 'd_convergence': 1e-10})
38 | psi4.set_module_options("pe", {"potfile": "pna_6w.pot"})
39 | scf_e, wfn = psi4.energy('SCF', return_wfn=True)
40 |
41 | # Run an adc2 calculation:
42 | state = adcc.adc2(wfn, n_singlets=5, conv_tol=1e-8,
43 | environment=True)
44 | print(state.describe())
45 |
--------------------------------------------------------------------------------
/examples/environment/psi4_adc2_pna_ptlr_ddx.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import adcc
3 |
4 | import psi4
5 |
6 | # Run PCM SCF in psi4
7 | mol = psi4.geometry("""
8 | C 8.64800 1.07500 -1.71100
9 | C 9.48200 0.43000 -0.80800
10 | C 9.39600 0.75000 0.53800
11 | C 8.48200 1.71200 0.99500
12 | C 7.65300 2.34500 0.05500
13 | C 7.73200 2.03100 -1.29200
14 | H 10.18300 -0.30900 -1.16400
15 | H 10.04400 0.25200 1.24700
16 | H 6.94200 3.08900 0.38900
17 | H 7.09700 2.51500 -2.01800
18 | N 8.40100 2.02500 2.32500
19 | N 8.73400 0.74100 -3.12900
20 | O 7.98000 1.33100 -3.90100
21 | O 9.55600 -0.11000 -3.46600
22 | H 7.74900 2.71100 2.65200
23 | H 8.99100 1.57500 2.99500
24 | symmetry c1
25 | no_reorient
26 | no_com
27 | """)
28 |
29 | psi4.set_options({
30 | 'basis': "sto-3g",
31 | 'scf_type': 'pk',
32 | 'e_convergence': 1e-10,
33 | 'd_convergence': 1e-10,
34 | 'ddx': True,
35 | 'ddx_model': "pcm",
36 | 'ddx_solvent': "water",
37 | 'ddx_radii_set': 'uff',
38 | 'ddx_radii_scaling': 1.2,
39 | 'ddx_solvation_convergence': 1e-10,
40 | })
41 | psi4.core.set_num_threads(4)
42 |
43 | scf_e, wfn = psi4.energy('scf', return_wfn=True)
44 |
45 | # Run an ADC2 calculation with ptLR
46 | state = adcc.adc2(wfn, n_singlets=5, conv_tol=1e-8, environment="ptlr")
47 | print(state.describe())
48 |
--------------------------------------------------------------------------------
/examples/environment/psi4_adc2_pna_ptlr_pcm.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import adcc
3 |
4 | import psi4
5 |
6 | # Run PCM SCF in psi4
7 | mol = psi4.geometry("""
8 | C 8.64800 1.07500 -1.71100
9 | C 9.48200 0.43000 -0.80800
10 | C 9.39600 0.75000 0.53800
11 | C 8.48200 1.71200 0.99500
12 | C 7.65300 2.34500 0.05500
13 | C 7.73200 2.03100 -1.29200
14 | H 10.18300 -0.30900 -1.16400
15 | H 10.04400 0.25200 1.24700
16 | H 6.94200 3.08900 0.38900
17 | H 7.09700 2.51500 -2.01800
18 | N 8.40100 2.02500 2.32500
19 | N 8.73400 0.74100 -3.12900
20 | O 7.98000 1.33100 -3.90100
21 | O 9.55600 -0.11000 -3.46600
22 | H 7.74900 2.71100 2.65200
23 | H 8.99100 1.57500 2.99500
24 | symmetry c1
25 | no_reorient
26 | no_com
27 | """)
28 |
29 | psi4.set_options({
30 | 'basis': "sto-3g",
31 | 'scf_type': 'pk',
32 | 'e_convergence': 1e-10,
33 | 'd_convergence': 1e-10,
34 | 'pcm': True,
35 | 'pcm_scf_type': "total"
36 | })
37 | psi4.pcm_helper("""
38 | Units = AU
39 | Cavity {
40 | Type = GePol
41 | radiiset = uff
42 | Scaling = True
43 | Area = 0.3
44 | }
45 | Medium {
46 | SolverType = IEFPCM
47 | Solvent = Water
48 | Nonequilibrium = True
49 | }
50 | """)
51 |
52 | psi4.core.set_num_threads(4)
53 |
54 | scf_e, wfn = psi4.energy('scf', return_wfn=True)
55 |
56 | # Run an ADC2 calculation with ptLR
57 | state = adcc.adc2(wfn, n_singlets=5, conv_tol=1e-8, environment="ptlr")
58 | print(state.describe())
59 |
--------------------------------------------------------------------------------
/examples/environment/psi4_adc2_pna_ss_ddx.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import adcc
3 |
4 | import psi4
5 |
6 | # Run PCM SCF in psi4
7 | mol = psi4.geometry("""
8 | C 8.64800 1.07500 -1.71100
9 | C 9.48200 0.43000 -0.80800
10 | C 9.39600 0.75000 0.53800
11 | C 8.48200 1.71200 0.99500
12 | C 7.65300 2.34500 0.05500
13 | C 7.73200 2.03100 -1.29200
14 | H 10.18300 -0.30900 -1.16400
15 | H 10.04400 0.25200 1.24700
16 | H 6.94200 3.08900 0.38900
17 | H 7.09700 2.51500 -2.01800
18 | N 8.40100 2.02500 2.32500
19 | N 8.73400 0.74100 -3.12900
20 | O 7.98000 1.33100 -3.90100
21 | O 9.55600 -0.11000 -3.46600
22 | H 7.74900 2.71100 2.65200
23 | H 8.99100 1.57500 2.99500
24 | symmetry c1
25 | no_reorient
26 | no_com
27 | units angstrom
28 | """)
29 |
30 | psi4.set_options({
31 | 'basis': "sto-3g",
32 | 'scf_type': 'pk',
33 | 'e_convergence': 1e-10,
34 | 'd_convergence': 1e-10,
35 | 'ddx': True,
36 | 'ddx_model': "pcm",
37 | 'ddx_solvent': "water",
38 | 'ddx_radii_set': 'uff',
39 | 'ddx_radii_scaling': 1.2,
40 | 'ddx_solvation_convergence': 1e-10,
41 | })
42 | psi4.core.set_num_threads(4)
43 |
44 | scf_e, wfn = psi4.energy('scf', return_wfn=True)
45 |
46 | # Run an ADC2 calculation with ptLR
47 | state = adcc.adc2(wfn, n_singlets=5, conv_tol=1e-8, environment="linear_response")
48 | print(state.describe())
49 |
--------------------------------------------------------------------------------
/examples/environment/pyscf_adc2_pna_6w_pol_embed.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 |
4 | import adcc
5 | from pyscf import gto, scf
6 | from pyscf.solvent import PE
7 |
8 | from scipy import constants
9 | eV = constants.value("Hartree energy in eV") # Hartree to eV
10 |
11 | mol = gto.M(
12 | atom="""
13 | C 8.64800 1.07500 -1.71100
14 | C 9.48200 0.43000 -0.80800
15 | C 9.39600 0.75000 0.53800
16 | C 8.48200 1.71200 0.99500
17 | C 7.65300 2.34500 0.05500
18 | C 7.73200 2.03100 -1.29200
19 | H 10.18300 -0.30900 -1.16400
20 | H 10.04400 0.25200 1.24700
21 | H 6.94200 3.08900 0.38900
22 | H 7.09700 2.51500 -2.01800
23 | N 8.40100 2.02500 2.32500
24 | N 8.73400 0.74100 -3.12900
25 | O 7.98000 1.33100 -3.90100
26 | O 9.55600 -0.11000 -3.46600
27 | H 7.74900 2.71100 2.65200
28 | H 8.99100 1.57500 2.99500
29 | """,
30 | basis='sto-3g',
31 | )
32 |
33 | scfres = PE(scf.RHF(mol), {"potfile": "pna_6w.pot"})
34 | scfres.conv_tol = 1e-8
35 | scfres.conv_tol_grad = 1e-6
36 | scfres.max_cycle = 250
37 | scfres.kernel()
38 |
39 | # model the solvent through perturbative corrections
40 | state_pt = adcc.adc2(scfres, n_singlets=5, conv_tol=1e-5,
41 | environment=['ptss', 'ptlr'])
42 |
43 | # now model the solvent through linear-response coupling
44 | # in the ADC matrix, re-using the matrix from previous run.
45 | # This will modify state_pt.matrix
46 | state_lr = adcc.run_adc(state_pt.matrix, n_singlets=5, conv_tol=1e-5,
47 | environment='linear_response')
48 |
49 | print(state_pt.describe())
50 | print(state_lr.describe())
51 |
--------------------------------------------------------------------------------
/examples/environment/pyscf_adc2_pna_lr_pcm.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import adcc
4 | from pyscf import gto, scf
5 | from pyscf.solvent import ddCOSMO
6 |
7 | # Run PCM SCF in pyscf
8 | mol = gto.M(
9 | atom="""
10 | C 8.64800 1.07500 -1.71100
11 | C 9.48200 0.43000 -0.80800
12 | C 9.39600 0.75000 0.53800
13 | C 8.48200 1.71200 0.99500
14 | C 7.65300 2.34500 0.05500
15 | C 7.73200 2.03100 -1.29200
16 | H 10.18300 -0.30900 -1.16400
17 | H 10.04400 0.25200 1.24700
18 | H 6.94200 3.08900 0.38900
19 | H 7.09700 2.51500 -2.01800
20 | N 8.40100 2.02500 2.32500
21 | N 8.73400 0.74100 -3.12900
22 | O 7.98000 1.33100 -3.90100
23 | O 9.55600 -0.11000 -3.46600
24 | H 7.74900 2.71100 2.65200
25 | H 8.99100 1.57500 2.99500
26 | """,
27 | basis='sto-3g', symmetry=0, charge=0, spin=0,
28 | unit="Angström"
29 | )
30 |
31 | mf = ddCOSMO(scf.RHF(mol))
32 | # set the dielectric constant
33 | mf.with_solvent.eps = 78.36
34 | mf.conv_tol = 1e-8
35 | mf.conv_tol_grad = 1e-7
36 | mf.max_cycle = 150
37 |
38 | mf.kernel()
39 |
40 | # Run ADC2 with with linear-response for the solvent
41 |
42 | # first the dielectric constant needs to be adjusted to
43 | # the corresponding optical dielectric constant.
44 | # Note that this is also necessary for the ptlr scheme.
45 | mf.with_solvent.eps = 1.78
46 | state = adcc.adc2(mf, n_singlets=5, conv_tol=1e-6,
47 | environment="linear_response")
48 | print(state.describe())
49 |
--------------------------------------------------------------------------------
/examples/environment/setup_environment.sh:
--------------------------------------------------------------------------------
1 | THISDIR=$(dirname "${BASH_SOURCE[0]}")
2 | export PYTHONPATH="$THISDIR/../..:$PYTHONPATH"
3 | unset THISDIR
4 |
--------------------------------------------------------------------------------
/examples/hydrogen_fluoride/.gitignore:
--------------------------------------------------------------------------------
1 | 631g_adc2_dissociation.nptxt
2 |
--------------------------------------------------------------------------------
/examples/hydrogen_fluoride/psi4_631g_sf_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import psi4
5 |
6 | # Run SCF in psi4
7 | mol = psi4.geometry("""
8 | 0 3
9 | H 0 0 0
10 | F 0 0 2.5
11 | symmetry c1
12 | units au
13 | no_reorient
14 | no_com
15 | """)
16 |
17 | psi4.set_num_threads(adcc.get_n_threads())
18 | psi4.core.be_quiet()
19 | psi4.set_options({'basis': "6-31g",
20 | 'e_convergence': 1e-14,
21 | 'd_convergence': 1e-9,
22 | 'reference': 'uhf'})
23 | scf_e, wfn = psi4.energy('SCF', return_wfn=True)
24 |
25 | # Run solver and print results
26 | states = adcc.adc2(wfn, n_spin_flip=5, conv_tol=1e-8)
27 | print(states.describe())
28 | print(states.describe_amplitudes())
29 |
--------------------------------------------------------------------------------
/examples/hydrogen_fluoride/pyscf_631g_sf_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | from pyscf import gto, scf
5 |
6 | # Run SCF in pyscf
7 | mol = gto.M(
8 | atom='H 0 0 0;'
9 | 'F 0 0 2.5',
10 | basis='6-31G',
11 | unit="Bohr",
12 | spin=2 # =2S, ergo triplet
13 | )
14 | scfres = scf.UHF(mol)
15 | scfres.conv_tol = 1e-14
16 | scfres.conv_tol_grad = 1e-10
17 | scfres.max_cycle = 500
18 | scfres.kernel()
19 |
20 | # Run solver and print results
21 | states = adcc.adc2(scfres, n_spin_flip=5, conv_tol=1e-8)
22 | print(states.describe())
23 |
24 | # Plot the excitation spectrum
25 | s2s = adcc.State2States(states, initial=0)
26 | s2s.plot_spectrum()
27 |
--------------------------------------------------------------------------------
/examples/hydrogen_fluoride/pyscf_631g_sf_adc2_dissociation.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import os
4 | import adcc
5 | import numpy as np
6 |
7 | from pyscf import gto, scf
8 | from matplotlib import pyplot as plt
9 |
10 |
11 | def run_spin_flip(distance):
12 | # Run SCF in pyscf
13 | mol = gto.M(
14 | atom='H 0 0 0;'
15 | 'F 0 0 {}'.format(distance),
16 | basis='6-31G',
17 | unit="Bohr",
18 | spin=2 # =2S, ergo triplet
19 | )
20 | scfres = scf.UHF(mol)
21 | scfres.conv_tol = 1e-12
22 | scfres.conv_tol_grad = 1e-8
23 | scfres.kernel()
24 |
25 | # Run ADC and compute total energy
26 | states = adcc.adc2(scfres, n_spin_flip=1)
27 |
28 | ene = scfres.energy_tot() + states.ground_state.energy_correction(2)
29 | return ene + states.excitation_energy[0]
30 |
31 |
32 | def run_progression(outfile="631g_adc2_dissociation.nptxt"):
33 | if os.path.isfile(outfile):
34 | return np.loadtxt(outfile)
35 |
36 | dists = np.linspace(1.0, 5.0, 30)
37 | enes = [run_spin_flip(d) for d in dists]
38 |
39 | result = np.vstack((dists, enes)).T
40 | np.savetxt(outfile, result)
41 | return result
42 |
43 |
44 | def main():
45 | result = run_progression()
46 | plt.plot(result[:, 0], result[:, 1])
47 | plt.show()
48 |
49 |
50 | if __name__ == "__main__":
51 | main()
52 |
--------------------------------------------------------------------------------
/examples/methyloxirane/pyscf_631g_adc2_ecd.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 | from matplotlib import pyplot as plt
7 |
8 | enantiomers = {
9 | "(S)-2-methyloxirane": """
10 | O 0.7971066654 0.9044360742 0.0836962049
11 | C -0.1867183086 -0.0290724859 0.5536827176
12 | C -1.4336843546 -0.1726679227 -0.2822214295
13 | C 1.1302222000 -0.4892393880 0.0894444115
14 | H 1.2197487995 -0.9517340291 -0.8946449424
15 | H 1.8923895176 -0.7869225283 0.8107731933
16 | H -0.3474086480 0.0162374592 1.6337796505
17 | H -2.0955293870 0.6891134744 -0.1384941617
18 | H -1.9883466588 -1.0759327249 -0.0005360999
19 | H -1.1805969868 -0.2349473270 -1.3455182514
20 | """,
21 | "(R)-2-methyloxirane": """
22 | O -0.8328602577 0.7897730814 -0.2375616734
23 | C 0.1486158153 0.0360794279 0.4890402083
24 | H 0.1511355430 0.2453732348 1.5616840340
25 | C -1.0455791318 -0.6173265887 -0.0661148292
26 | H -1.8751757963 -0.8906447658 0.5872264586
27 | H -0.9556948808 -1.2169886069 -0.9730489338
28 | C 1.5085709521 -0.0930940130 -0.1498440685
29 | H 1.4131373959 -0.3116398357 -1.2181956153
30 | H 2.0766856596 0.8381684090 -0.0415125805
31 | H 2.0848517291 -0.8974263240 0.3232009602
32 | """
33 | }
34 |
35 |
36 | for molecule in enantiomers:
37 | molecular_geometry = enantiomers[molecule]
38 | mol = gto.M(
39 | atom=molecular_geometry,
40 | basis='6-31G',
41 | )
42 | scfres = scf.RHF(mol)
43 | scfres.conv_tol = 1e-10
44 | scfres.conv_tol_grad = 1e-8
45 | scfres.kernel()
46 |
47 | # Run an adc2 calculation:
48 | state = adcc.adc2(scfres, n_singlets=10, conv_tol=1e-5)
49 | print(state.describe(rotatory_strengths=True))
50 |
51 | # Plot rotatory strengths
52 | plots = state.plot_spectrum(yaxis="rotatory_strength", width=0.005,
53 | label=molecule)
54 | plt.legend()
55 | plt.show()
56 |
--------------------------------------------------------------------------------
/examples/methyloxirane/setup_environment.sh:
--------------------------------------------------------------------------------
1 | THISDIR=$(dirname "${BASH_SOURCE[0]}")
2 | export PYTHONPATH="$THISDIR/../..:$PYTHONPATH"
3 | unset THISDIR
4 |
--------------------------------------------------------------------------------
/examples/neon/setup_environment.sh:
--------------------------------------------------------------------------------
1 | THISDIR=$(dirname "${BASH_SOURCE[0]}")
2 | export PYTHONPATH="$PYTHONPATH:$THISDIR/../.."
3 | unset THISDIR
4 |
--------------------------------------------------------------------------------
/examples/neon/test_cg_alpha.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import numpy as np
5 |
6 | from pyscf import gto, scf
7 | from adcc.solver.preconditioner import JacobiPreconditioner
8 | from adcc.solver import IndexSymmetrisation
9 | from adcc.solver.conjugate_gradient import conjugate_gradient, default_print
10 | from adcc.adc_pp.modified_transition_moments import modified_transition_moments
11 |
12 |
13 | class ShiftedMat(adcc.AdcMatrix):
14 | def __init__(self, method, mp_results, omega=0.0):
15 | self.omega = omega
16 | super().__init__(method, mp_results)
17 | self.omegamat = adcc.ones_like(self.diagonal()) * omega
18 |
19 | def __matmul__(self, other):
20 | return super().__matmul__(other) - self.omegamat * other
21 |
22 |
23 | # Run SCF in pyscf
24 | mol = gto.M(
25 | atom="""
26 | Ne
27 | """,
28 | basis='aug-cc-pvdz',
29 | unit="Bohr"
30 | )
31 | scfres = scf.RHF(mol)
32 | scfres.conv_tol = 1e-12
33 | scfres.conv_tol_grad = 1e-9
34 | scfres.kernel()
35 |
36 | refstate = adcc.ReferenceState(scfres)
37 | matrix = ShiftedMat("adc3", refstate, omega=0.0)
38 | rhs = modified_transition_moments("adc2", matrix.ground_state,
39 | refstate.operators.electric_dipole[0])
40 | preconditioner = JacobiPreconditioner(matrix)
41 | freq = 0.0
42 | preconditioner.update_shifts(freq)
43 |
44 | explicit_symmetrisation = IndexSymmetrisation(matrix)
45 |
46 | x0 = preconditioner.apply(rhs)
47 | res = conjugate_gradient(matrix, rhs=rhs, x0=x0, callback=default_print,
48 | Pinv=preconditioner, conv_tol=1e-4,
49 | explicit_symmetrisation=explicit_symmetrisation)
50 |
51 | alpha_xx = 2.0 * res.solution @ rhs
52 | np.testing.assert_allclose(alpha_xx, 1.994, atol=1e-3)
53 | print("alpha_xx(0) = ", alpha_xx)
54 |
--------------------------------------------------------------------------------
/examples/sulfur_hydride/pyscf_ccpvtz_arbitrary_cvs_adc2x.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 | from matplotlib import pyplot as plt
7 |
8 | # Run SCF in pyscf
9 | mol = gto.M(
10 | atom='S -0.38539679062 0 -0.27282082253;'
11 | 'H -0.0074283962687 0 2.2149138578;'
12 | 'H 2.0860198029 0 -0.74589639249',
13 | basis='cc-pvtz',
14 | unit="Bohr"
15 | )
16 | scfres = scf.RHF(mol)
17 | scfres.conv_tol = 1e-13
18 | scfres.kernel()
19 | nmo = mol.nao
20 |
21 | scfres.analyze()
22 |
23 | print()
24 | print("=========== CVS (1s to 2s) ================")
25 | print()
26 | singlets = adcc.cvs_adc2x(scfres, core_orbitals=2, n_singlets=10)
27 | print(singlets.describe())
28 | singlets.plot_spectrum(label="H2S CVS (1s and 2s)")
29 |
30 |
31 | print()
32 | print("=========== CVS (2s) ================")
33 | print()
34 | singlets = adcc.cvs_adc2x(scfres, core_orbitals=[1, 1 + nmo], n_singlets=10)
35 | print(singlets.describe())
36 | singlets.plot_spectrum(label="H2S CVS (2s)")
37 |
38 | plt.legend()
39 | plt.savefig("pyscf_ccpvtz_arbitrary_cvs_adc2x.pdf")
40 |
--------------------------------------------------------------------------------
/examples/sulfur_hydride/pyscf_ccpvtz_fc_cvs_adc2x.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | from pyscf import gto, scf
4 |
5 | import adcc
6 |
7 | # Run SCF in pyscf
8 | mol = gto.M(
9 | atom='S -0.38539679062 0 -0.27282082253;'
10 | 'H -0.0074283962687 0 2.2149138578;'
11 | 'H 2.0860198029 0 -0.74589639249',
12 | basis='cc-pvtz',
13 | unit="Bohr"
14 | )
15 | scfres = scf.RHF(mol)
16 | scfres.conv_tol = 1e-13
17 | scfres.kernel()
18 |
19 | print(adcc.banner())
20 |
21 | # Run an adc2x calculation:
22 | singlets = adcc.cvs_adc2x(scfres, core_orbitals=1, frozen_core=1, n_singlets=3)
23 | triplets = adcc.cvs_adc2x(singlets.matrix, n_triplets=3)
24 |
25 | print(singlets.describe())
26 | print()
27 | print(triplets.describe())
28 |
--------------------------------------------------------------------------------
/examples/sulfur_hydride/pyscf_geoopt_mp2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from pyscf import gto, mp, scf
3 | from pyscf.geomopt import berny_solver
4 |
5 | # Starting geometry
6 | mol = gto.M(
7 | atom='S 0 0 0;'
8 | 'H 0 0 1.795239827225189;'
9 | 'H 1.693194615993441 0 -0.599043184453037',
10 | basis='cc-pvtz',
11 | verbose=3,
12 | unit="Bohr"
13 | )
14 |
15 | # HF optimisation
16 | mf = scf.RHF(mol)
17 | mol_hf_eq = berny_solver.optimize(mf)
18 |
19 | # MP2 optimisation
20 | mp2 = mp.MP2(scf.RHF(mol_hf_eq))
21 | mol_mp2_eq = berny_solver.optimize(mp2)
22 |
23 |
24 | print()
25 | print("=========== Final MP2 geometry (bohr) ============")
26 | print()
27 | fmt = "{} {:15.11g} {:15.11g} {:15.11g}"
28 | coords = mol_mp2_eq.atom_coords()
29 | n_atoms = len(coords)
30 | for i in range(n_atoms):
31 | print(fmt.format(mol_mp2_eq.atom_symbol(i), *coords[i]))
32 |
--------------------------------------------------------------------------------
/examples/water/.gitignore:
--------------------------------------------------------------------------------
1 | # psi4
2 | timer.dat
3 | *.clean
4 | *_spectrum.pdf
5 |
--------------------------------------------------------------------------------
/examples/water/import_data.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import numpy as np
4 |
5 | from data import coeff_data, dip_data, eri_data, orben_data
6 |
7 |
8 | def import_data():
9 | n_orbs_alpha = n_bas = 7
10 | n_orbs = 2 * n_orbs_alpha
11 | data = {
12 | "n_orbs_alpha": n_orbs_alpha,
13 | "n_bas": n_bas,
14 | "energy_scf": -7.4959319286025718e+01,
15 | "restricted": True,
16 | "threshold": 1e-12,
17 | "spin_multiplicity": 1,
18 | "multipoles": {
19 | "elec_0": -10,
20 | "nuclear_0": 10,
21 | "nuclear_1": np.array([1.693194615993441, 0.,
22 | 1.196196642772152]),
23 | "elec_1": np.array(dip_data).reshape(3, n_bas, n_bas)
24 | },
25 | }
26 | data["occupation_f"] = np.array(5 * [1] + [0, 0] + 5 * [1] + [0, 0.])
27 | data["orbcoeff_fb"] = np.array(coeff_data).reshape((n_orbs, n_bas))
28 | data["orben_f"] = np.array(orben_data).reshape((n_orbs))
29 | data["eri_ffff"] = np.array(eri_data).reshape((n_orbs, n_orbs,
30 | n_orbs, n_orbs))
31 |
32 | data["fock_ff"] = np.zeros((n_orbs, n_orbs))
33 | for i in range(n_orbs):
34 | data["fock_ff"][i, i] = orben_data[i]
35 | return data
36 |
--------------------------------------------------------------------------------
/examples/water/molsturm_sto3g_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | import molsturm
6 |
7 | # Run SCF in molsturm
8 | atoms = ["O", "H", "H"]
9 | coords = [[0, 0, 0],
10 | [0, 0, 1.795239827225189],
11 | [1.693194615993441, 0, -0.599043184453037]]
12 | system = molsturm.System(atoms, coords)
13 |
14 | hfres = molsturm.hartree_fock(system, basis_type="gaussian",
15 | basis_set_name="sto-3g",
16 | conv_tol=1e-12, print_iterations=True)
17 |
18 | # Run an adc2 calculation:
19 | singlets = adcc.adc2(hfres, n_singlets=5, conv_tol=1e-9)
20 | triplets = adcc.adc2(singlets.matrix, n_triplets=3, conv_tol=1e-9)
21 |
22 | print(singlets.describe())
23 | print(triplets.describe())
24 |
--------------------------------------------------------------------------------
/examples/water/psi4_ccpvdz_adc2_spectrum.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import psi4
5 |
6 | from matplotlib import pyplot as plt
7 |
8 | # Run SCF in psi4
9 | mol = psi4.geometry("""
10 | O 0 0 0
11 | H 0 0 1.795239827225189
12 | H 1.693194615993441 0 -0.599043184453037
13 | symmetry c1
14 | units au
15 | no_reorient
16 | no_com
17 | """)
18 |
19 | # set the number of cores equal to the auto-determined value from
20 | # the adcc ThreadPool
21 | psi4.set_num_threads(adcc.get_n_threads())
22 | psi4.core.be_quiet()
23 | psi4.set_options({'basis': "cc-pvdz",
24 | 'scf_type': 'pk',
25 | 'e_convergence': 1e-14,
26 | 'd_convergence': 1e-9})
27 | scf_e, wfn = psi4.energy('SCF', return_wfn=True)
28 |
29 | print(adcc.banner())
30 |
31 | # Run an adc2 calculation:
32 | state = adcc.adc2(wfn, n_singlets=7, conv_tol=1e-8)
33 |
34 | # Print results
35 | print()
36 | print(" st ex.ene. (au) f transition dipole moment (au)"
37 | " state dip (au)")
38 | for i, val in enumerate(state.excitation_energy):
39 | fmt = "{0:2d} {1:12.8g} {2:9.3g} [{3:9.3g}, {4:9.3g}, {5:9.3g}]"
40 | fmt += " [{6:9.3g}, {7:9.3g}, {8:9.3g}]"
41 | print(state.kind[0], fmt.format(i, val, state.oscillator_strength[i],
42 | *state.transition_dipole_moment[i],
43 | *state.state_dipole_moment[i]))
44 |
45 | state.plot_spectrum()
46 | plt.savefig("psi4_ccpvdz_adc2_spectrum.pdf")
47 | plt.show()
48 |
49 | # Print timings summary:
50 | print()
51 | print(state.timer.describe())
52 |
--------------------------------------------------------------------------------
/examples/water/psi4_ccpvdz_cvs_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import psi4
5 |
6 | from matplotlib import pyplot as plt
7 |
8 | mol = psi4.geometry("""
9 | O 0 0 0
10 | H 0 0 1.795239827225189
11 | H 1.693194615993441 0 -0.599043184453037
12 | symmetry c1
13 | units au
14 | """)
15 |
16 | # set the number of cores equal to the auto-determined value from
17 | # the adcc ThreadPool
18 | psi4.set_num_threads(adcc.get_n_threads())
19 | psi4.core.be_quiet()
20 | psi4.set_options({'basis': "cc-pvdz",
21 | 'scf_type': 'pk',
22 | 'e_convergence': 1e-12,
23 | 'd_convergence': 1e-8})
24 | scf_e, wfn = psi4.energy('SCF', return_wfn=True)
25 |
26 | # Run an adc2 calculation:
27 | state = adcc.cvs_adc2(wfn, n_singlets=5, core_orbitals=1)
28 |
29 | print(state.describe())
30 |
31 | state.plot_spectrum()
32 | plt.savefig("psi4_ccpvdz_cvs_adc2_spectrum.pdf")
33 |
--------------------------------------------------------------------------------
/examples/water/psi4_sto3g_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import psi4
5 |
6 | mol = psi4.geometry("""
7 | O 0 0 0
8 | H 0 0 1.795239827225189
9 | H 1.693194615993441 0 -0.599043184453037
10 | symmetry c1
11 | units au
12 | """)
13 |
14 | # set the number of cores equal to the auto-determined value from
15 | # the adcc ThreadPool
16 | psi4.set_num_threads(adcc.get_n_threads())
17 | psi4.core.be_quiet()
18 | psi4.set_options({'basis': "sto-3g",
19 | 'scf_type': 'pk',
20 | 'e_convergence': 1e-12,
21 | 'd_convergence': 1e-8})
22 | scf_e, wfn = psi4.energy('SCF', return_wfn=True)
23 |
24 | # Run an adc2 calculation:
25 | state = adcc.adc2(wfn, n_singlets=5)
26 |
27 | print(state.describe())
28 |
--------------------------------------------------------------------------------
/examples/water/psi4_sto3g_uhf_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import psi4
5 |
6 | mol = psi4.geometry("""
7 | 0 3
8 | O 0 0 0
9 | H 0 0 1.795239827225189
10 | H 1.693194615993441 0 -0.599043184453037
11 | symmetry c1
12 | units au
13 | """)
14 |
15 | # set the number of cores equal to the auto-determined value from
16 | # the adcc ThreadPool
17 | psi4.set_num_threads(adcc.get_n_threads())
18 | psi4.core.be_quiet()
19 | psi4.set_options({'basis': "sto-3g",
20 | 'scf_type': 'pk',
21 | 'e_convergence': 1e-12,
22 | 'reference': 'uhf',
23 | 'd_convergence': 1e-8})
24 | scf_e, wfn = psi4.energy('SCF', return_wfn=True)
25 |
26 | # Run an adc2 calculation:
27 | state = adcc.adc2(wfn, n_states=5)
28 |
29 | print(state.describe())
30 |
--------------------------------------------------------------------------------
/examples/water/pyscf_ccpvdz_adc2_spectrum.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 | from matplotlib import pyplot as plt
7 |
8 | # Run SCF in pyscf
9 | mol = gto.M(
10 | atom='O 0 0 0;'
11 | 'H 0 0 1.795239827225189;'
12 | 'H 1.693194615993441 0 -0.599043184453037',
13 | basis='cc-pvdz',
14 | unit="Bohr"
15 | )
16 | scfres = scf.RHF(mol)
17 | scfres.conv_tol = 1e-12
18 | scfres.conv_tol_grad = 1e-9
19 | scfres.kernel()
20 |
21 | print(adcc.banner())
22 |
23 | # Run an adc2 calculation:
24 | state = adcc.adc2(scfres, n_singlets=7, conv_tol=1e-8)
25 |
26 | # Print results
27 | print()
28 | print(" st ex.ene. (au) f transition dipole moment (au)"
29 | " state dip (au)")
30 | for i, val in enumerate(state.excitation_energy):
31 | fmt = "{0:2d} {1:12.8g} {2:9.3g} [{3:9.3g}, {4:9.3g}, {5:9.3g}]"
32 | fmt += " [{6:9.3g}, {7:9.3g}, {8:9.3g}]"
33 | print(state.kind[0], fmt.format(i, val, state.oscillator_strength[i],
34 | *state.transition_dipole_moment[i],
35 | *state.state_dipole_moment[i]))
36 | print(state.excitation_energies)
37 | state.plot_spectrum()
38 | plt.savefig("pyscf_ccpvdz_adc2_spectrum.pdf")
39 | plt.show()
40 |
41 | # Print timings summary:
42 | print()
43 | print(state.timer.describe())
44 |
--------------------------------------------------------------------------------
/examples/water/pyscf_ccpvdz_adc3_comparison.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 | from matplotlib import pyplot as plt
7 |
8 | # Run SCF in pyscf
9 | mol = gto.M(
10 | atom='O 0 0 0;'
11 | 'H 0 0 1.795239827225189;'
12 | 'H 1.693194615993441 0 -0.599043184453037',
13 | basis='cc-pvdz',
14 | unit="Bohr"
15 | )
16 | scfres = scf.RHF(mol)
17 | scfres.conv_tol = 1e-13
18 | scfres.kernel()
19 |
20 | # Run an adc3 calculation:
21 | singlets = adcc.adc3(scfres, n_singlets=3) # noqa: E221
22 | singlets_fc = adcc.adc3(scfres, frozen_core=1, n_singlets=3) # noqa: E221
23 | singlets_fv2 = adcc.adc3(scfres, frozen_virtual=2, n_singlets=3) # noqa: E221
24 | singlets_fv4 = adcc.adc3(scfres, frozen_virtual=4, n_singlets=3) # noqa: E221
25 | singlets_fv6 = adcc.adc3(scfres, frozen_virtual=6, n_singlets=3) # noqa: E221
26 | singlets_fv8 = adcc.adc3(scfres, frozen_virtual=8, n_singlets=3) # noqa: E221
27 | singlets.plot_spectrum(label="ADC(3)")
28 | singlets_fc.plot_spectrum(label="FC-ADC(3)")
29 | singlets_fv2.plot_spectrum(label="FV-ADC(3) 2")
30 | singlets_fv4.plot_spectrum(label="FV-ADC(3) 4")
31 | singlets_fv6.plot_spectrum(label="FV-ADC(3) 6")
32 | singlets_fv8.plot_spectrum(label="FV-ADC(3) 8")
33 |
34 | plt.legend()
35 | plt.show()
36 |
--------------------------------------------------------------------------------
/examples/water/pyscf_ccpvdz_fc_adc3.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | from pyscf import gto, scf
4 |
5 | import adcc
6 |
7 | # Run SCF in pyscf
8 | mol = gto.M(
9 | atom='O 0 0 0;'
10 | 'H 0 0 1.795239827225189;'
11 | 'H 1.693194615993441 0 -0.599043184453037',
12 | basis='cc-pvdz',
13 | unit="Bohr"
14 | )
15 | scfres = scf.RHF(mol)
16 | scfres.conv_tol = 1e-13
17 | scfres.kernel()
18 |
19 | # Run an adc3 calculation:
20 | singlets = adcc.adc3(scfres, frozen_core=1, n_singlets=3)
21 | triplets = adcc.adc3(singlets.matrix, n_triplets=3)
22 |
23 | print(singlets.describe())
24 | print()
25 | print(triplets.describe())
26 |
--------------------------------------------------------------------------------
/examples/water/pyscf_ccpvdz_fv_adc3.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 |
7 | # Run SCF in pyscf
8 | mol = gto.M(
9 | atom='O 0 0 0;'
10 | 'H 0 0 1.795239827225189;'
11 | 'H 1.693194615993441 0 -0.599043184453037',
12 | basis='cc-pvdz',
13 | unit="Bohr"
14 | )
15 | scfres = scf.RHF(mol)
16 | scfres.conv_tol = 1e-13
17 | scfres.kernel()
18 |
19 | # Run an adc3 calculation:
20 | singlets = adcc.adc3(scfres, frozen_virtual=3, n_singlets=3)
21 | triplets = adcc.adc3(singlets.matrix, n_triplets=3)
22 |
23 | print(singlets.describe())
24 | print()
25 | print(triplets.describe())
26 |
--------------------------------------------------------------------------------
/examples/water/pyscf_ccpvdz_xes.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 | import copy
5 |
6 | from pyscf import gto, scf
7 | from matplotlib import pyplot as plt
8 |
9 | mol = gto.M(
10 | atom='O 0 0 0;'
11 | 'H 0 0 1.795239827225189;'
12 | 'H 1.693194615993441 0 -0.599043184453037',
13 | basis='cc-pvdz',
14 | unit="Bohr",
15 | verbose=0,
16 | )
17 |
18 | # Run normal SCF in pyscf
19 | mf = scf.UHF(mol)
20 | mf.conv_tol = 1e-13
21 | mf.conv_tol_grad = 1e-8
22 | mf.kernel()
23 | print("Water SCF energy", mf.energy_tot())
24 |
25 | # Make a core hole
26 | mo0 = copy.deepcopy(mf.mo_coeff)
27 | occ0 = copy.deepcopy(mf.mo_occ)
28 | occ0[1][0] = 0.0 # beta core hole
29 | dm = mf.make_rdm1(mo0, occ0)
30 |
31 | mf_core = scf.UHF(mol)
32 | mf_core.conv_tol = 1e-13
33 | mf_core.conv_tol_grad = 1e-8
34 | scf.addons.mom_occ(mf_core, mo0, occ0)
35 | mf_core.kernel(dm)
36 | del dm
37 | print("Water core hole energy", mf_core.energy_tot())
38 |
39 | # Run an adc2 calculation:
40 | state = adcc.adc2(mf_core, n_states=4)
41 |
42 | # Print results in a nice way
43 | print()
44 | print(" st ex.ene. (au) f transition dipole moment (au)"
45 | " state dip (au)")
46 | for i, val in enumerate(state.excitation_energy):
47 | fmt = "{0:2d} {1:12.8g} {2:9.3g} [{3:9.3g}, {4:9.3g}, {5:9.3g}]"
48 | fmt += " [{6:9.3g}, {7:9.3g}, {8:9.3g}]"
49 | print(state.kind[0], fmt.format(i, val, state.oscillator_strength[i],
50 | *state.transition_dipole_moment[i],
51 | *state.state_dipole_moment[i]))
52 |
53 | state.plot_spectrum()
54 | plt.savefig("pyscf_ccpvdz_xes_spectrum.pdf")
55 | plt.show()
56 |
57 | # Print timings summary:
58 | print()
59 | print(state.timer.describe())
60 |
--------------------------------------------------------------------------------
/examples/water/pyscf_ccpvtz_adc3.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 | from matplotlib import pyplot as plt
7 |
8 | # Run SCF in pyscf
9 | mol = gto.M(
10 | atom='O 0 0 0;'
11 | 'H 0 0 1.795239827225189;'
12 | 'H 1.693194615993441 0 -0.599043184453037',
13 | basis='cc-pvtz',
14 | unit="Bohr"
15 | )
16 | scfres = scf.RHF(mol)
17 | scfres.conv_tol = 1e-13
18 | scfres.kernel()
19 |
20 | print(adcc.banner())
21 |
22 | # Run an adc3 calculation:
23 | singlets = adcc.adc3(scfres, n_singlets=3)
24 | triplets = adcc.adc3(singlets.matrix, n_triplets=3)
25 |
26 | print(singlets.describe())
27 | print()
28 | print(triplets.describe())
29 |
30 | singlets.plot_spectrum()
31 | plt.show()
32 |
--------------------------------------------------------------------------------
/examples/water/pyscf_sto3g_adc1.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 |
7 | # Run SCF in pyscf
8 | mol = gto.M(
9 | atom='O 0 0 0;'
10 | 'H 0 0 1.795239827225189;'
11 | 'H 1.693194615993441 0 -0.599043184453037',
12 | basis='sto-3g',
13 | unit="Bohr"
14 | )
15 |
16 | # Run RHF SCF
17 | scfres = scf.RHF(mol)
18 | scfres.conv_tol = 1e-14
19 | scfres.conv_tol_grad = 1e-10
20 | scfres.kernel()
21 |
22 | # Run an adc1 calculation:
23 | state = adcc.adc1(scfres, n_singlets=5)
24 |
25 | print(state.describe())
26 |
--------------------------------------------------------------------------------
/examples/water/pyscf_sto3g_adc2.jl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env julia
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 |
4 | # An example how to use adcc from julia
5 | import PyCall
6 | import PyPlot
7 | pyscf = PyCall.pyimport("pyscf")
8 | adcc = PyCall.pyimport("adcc")
9 |
10 |
11 | mol = pyscf.gto.M(
12 | atom="""
13 | O 0 0 0;
14 | H 0 0 1.795239827225189;
15 | H 1.693194615993441 0 -0.599043184453037
16 | """,
17 | basis="6311g**",
18 | unit="Bohr"
19 | )
20 | scfres = pyscf.scf.RHF(mol)
21 | scfres.conv_tol = 1e-13
22 | scfres.conv_tol_grad = 1e-7
23 | scfres.kernel()
24 |
25 | # Run an adc2 calculation:
26 | singlets = adcc.adc2(scfres, n_singlets=5)
27 | triplets = adcc.adc2(singlets.matrix, n_triplets=3)
28 |
29 | # Attach state densities
30 | println(singlets.describe())
31 | println()
32 | println(triplets.describe())
33 |
--------------------------------------------------------------------------------
/examples/water/pyscf_sto3g_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 |
7 | # Run SCF in pyscf
8 | mol = gto.M(
9 | atom='O 0 0 0;'
10 | 'H 0 0 1.795239827225189;'
11 | 'H 1.693194615993441 0 -0.599043184453037',
12 | basis='sto-3g',
13 | unit="Bohr"
14 | )
15 | scfres = scf.RHF(mol)
16 | scfres.conv_tol = 1e-14
17 | scfres.conv_tol_grad = 1e-10
18 | scfres.kernel()
19 |
20 | # Run an adc2 calculation:
21 | singlets = adcc.adc2(scfres, n_singlets=5)
22 | triplets = adcc.adc2(singlets.matrix, n_triplets=3)
23 |
24 | print(singlets.describe())
25 | print()
26 | print(triplets.describe())
27 |
--------------------------------------------------------------------------------
/examples/water/pyscf_sto3g_uhf_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from pyscf import gto, scf
6 |
7 | # Run SCF in pyscf
8 | mol = gto.M(
9 | atom='O 0 0 0;'
10 | 'H 0 0 1.795239827225189;'
11 | 'H 1.693194615993441 0 -0.599043184453037',
12 | basis='sto-3g',
13 | spin=2,
14 | unit="Bohr"
15 | )
16 | scfres = scf.UHF(mol)
17 | scfres.conv_tol = 1e-8
18 | scfres.conv_tol_grad = 1e-8
19 | scfres.max_cycle = 100
20 | scfres.verbose = 4
21 | scfres.kernel()
22 |
23 | # Run an adc2 calculation:
24 | singlets = adcc.adc2(scfres, n_states=5)
25 |
26 | print(singlets.describe())
27 |
--------------------------------------------------------------------------------
/examples/water/setup_environment.sh:
--------------------------------------------------------------------------------
1 | THISDIR=$(dirname "${BASH_SOURCE[0]}")
2 | export PYTHONPATH="$THISDIR/../..:$PYTHONPATH"
3 | unset THISDIR
4 |
--------------------------------------------------------------------------------
/examples/water/sto3g_adc1.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather precomputed data
8 | data = import_data()
9 |
10 | # Run an adc1 calculation:
11 | singlets = adcc.adc1(data, n_singlets=5, conv_tol=1e-8)
12 | triplets = adcc.adc1(singlets.matrix, n_triplets=5, conv_tol=1e-8)
13 | print(singlets.describe())
14 | print(triplets.describe())
15 |
--------------------------------------------------------------------------------
/examples/water/sto3g_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather precomputed data
8 | data = import_data()
9 |
10 | # Run an adc2 calculation:
11 | singlets = adcc.adc2(data, n_singlets=5, conv_tol=1e-8)
12 | triplets = adcc.adc2(singlets.matrix, n_triplets=5, conv_tol=1e-8)
13 | print(singlets.describe())
14 | print(triplets.describe())
15 |
--------------------------------------------------------------------------------
/examples/water/sto3g_adc2x.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather precomputed data
8 | data = import_data()
9 |
10 | # Run an adc2x calculation:
11 | singlets = adcc.adc2x(data, n_singlets=5, conv_tol=1e-8)
12 | triplets = adcc.adc2x(singlets.matrix, n_triplets=5, conv_tol=1e-8)
13 | print(singlets.describe())
14 | print(triplets.describe())
15 |
--------------------------------------------------------------------------------
/examples/water/sto3g_adc3.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather precomputed data
8 | data = import_data()
9 |
10 | # Run an adc3 calculation:
11 | singlets = adcc.adc3(data, n_singlets=3, conv_tol=1e-8)
12 | triplets = adcc.adc3(singlets.matrix, n_triplets=4, conv_tol=1e-8)
13 | print(singlets.describe())
14 | print(triplets.describe())
15 |
--------------------------------------------------------------------------------
/examples/water/sto3g_cvs_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather preliminary data
8 | data = import_data()
9 |
10 | # Run an cvs-adc2 calculation:
11 | singlets = adcc.cvs_adc2(data, core_orbitals=1, n_singlets=1, conv_tol=1e-8)
12 | triplets = adcc.cvs_adc2(singlets.matrix, n_triplets=2, conv_tol=1e-8)
13 | # Note: Above core_orbitals is not required again, since the precise CVS
14 | # splitting is already encoded in the matrix.
15 |
16 | print(singlets.describe())
17 | print(triplets.describe())
18 |
--------------------------------------------------------------------------------
/examples/water/sto3g_fc_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather precomputed data
8 | data = import_data()
9 |
10 | # Run an adc2 calculation:
11 | singlets = adcc.adc2(data, frozen_core=1, n_singlets=5, conv_tol=1e-8)
12 | triplets = adcc.adc2(singlets.matrix, frozen_core=1, n_triplets=5, conv_tol=1e-8)
13 | print(singlets.describe())
14 | print(triplets.describe())
15 |
--------------------------------------------------------------------------------
/examples/water/sto3g_uadc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import adcc
4 |
5 | from import_data import import_data
6 |
7 | # Gather precomputed data
8 | data = import_data()
9 |
10 | # Make it unrestricted
11 | data["restricted"] = False
12 |
13 | # Run an unrestricted adc2 calculation:
14 | states = adcc.adc2(data, n_states=10, conv_tol=1e-8)
15 | print(states.describe())
16 |
--------------------------------------------------------------------------------
/examples/water/tpa.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | """Example computing the TPA cross section for water using ADC
4 | (10.1063/1.3682324)
5 | """
6 | import adcc
7 | import numpy as np
8 |
9 | from pyscf import gto, scf
10 | from adcc.solver.preconditioner import JacobiPreconditioner
11 | from adcc.solver import IndexSymmetrisation
12 | from adcc.solver.conjugate_gradient import conjugate_gradient, default_print
13 | from adcc.adc_pp.modified_transition_moments import modified_transition_moments
14 | from adcc.IsrMatrix import IsrMatrix
15 |
16 |
17 | class ShiftedMat(adcc.AdcMatrix):
18 | def __init__(self, method, mp_results, omega=0.0):
19 | self.omega = omega
20 | super().__init__(method, mp_results)
21 | self.omegamat = adcc.ones_like(self.diagonal()) * omega
22 |
23 | def __matmul__(self, other):
24 | return super().__matmul__(other) - self.omegamat * other
25 |
26 |
27 | # Run SCF in pyscf
28 | mol = gto.M(
29 | atom='O 0 0 0;'
30 | 'H 0 0 1.795239827225189;'
31 | 'H 1.693194615993441 0 -0.599043184453037',
32 | basis='aug-cc-pvdz',
33 | unit="Bohr"
34 | )
35 | scfres = scf.RHF(mol)
36 | scfres.conv_tol = 1e-12
37 | scfres.conv_tol_grad = 1e-9
38 | scfres.kernel()
39 |
40 | # solve for Eigenvalues
41 | state = adcc.adc2(scfres, n_singlets=1, conv_tol=1e-8)
42 |
43 | # setup modified transition moments
44 | dips = state.reference_state.operators.electric_dipole
45 | rhss = modified_transition_moments("adc2", state.ground_state, dips)
46 | isrmatrix = IsrMatrix("adc2", state.ground_state, dips)
47 |
48 | S = np.zeros((len(state.excitation_energy), 3, 3))
49 | for f, ee in enumerate(state.excitation_energy):
50 | freq = ee / 2.0
51 | matrix = ShiftedMat("adc2", state.ground_state, freq)
52 | preconditioner = JacobiPreconditioner(matrix)
53 | explicit_symmetrisation = IndexSymmetrisation(matrix)
54 | preconditioner.update_shifts(freq)
55 | response = []
56 | # solve all systems of equations
57 | for mu in range(3):
58 | rhs = rhss[mu]
59 | x0 = preconditioner.apply(rhs)
60 | res = conjugate_gradient(
61 | matrix, rhs=rhs, x0=x0, callback=default_print,
62 | Pinv=preconditioner, conv_tol=1e-6,
63 | explicit_symmetrisation=explicit_symmetrisation
64 | )
65 | response.append(res)
66 | right_vec = isrmatrix @ state.excitation_vector[f]
67 | for mu in range(3):
68 | for nu in range(mu, 3):
69 | # compute the matrix element
70 | S[f, mu, nu] = (
71 | response[mu].solution @ right_vec[nu]
72 | + response[nu].solution @ right_vec[mu]
73 | )
74 | S[f, nu, mu] = S[f, mu, nu]
75 | print("Two-Photon Matrix for state", f)
76 | print(S[f])
77 | delta = 1.0 / 15.0 * (
78 | np.einsum('mm,vv->', S[f], S[f])
79 | + np.einsum('mv,mv->', S[f], S[f])
80 | + np.einsum('mv,vm->', S[f], S[f])
81 | )
82 | print("TPA Cross section [a.u.]: {:.4f}".format(delta))
83 | np.testing.assert_allclose(6.5539, delta, atol=1e-4)
84 |
--------------------------------------------------------------------------------
/examples/water/veloxchem_ccpvdz_adc2_spectrum.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import os
4 | import adcc
5 | import tempfile
6 |
7 | from mpi4py import MPI
8 | from matplotlib import pyplot as plt
9 |
10 | import veloxchem as vlx
11 | from veloxchem.mpitask import MpiTask
12 |
13 | # Run SCF in VeloxChem
14 | with tempfile.TemporaryDirectory() as tmpdir:
15 | infile = os.path.join(tmpdir, "vlx.in")
16 | outfile = os.path.join(tmpdir, "/dev/null")
17 |
18 | with open(infile, "w") as fp:
19 | fp.write("""
20 | @jobs
21 | task: hf
22 | @end
23 |
24 | @method settings
25 | basis: cc-pvdz
26 | @end
27 |
28 | @molecule
29 | charge: 0
30 | multiplicity: 1
31 | units: bohr
32 | xyz:
33 | O 0 0 0
34 | H 0 0 1.795239827225189
35 | H 1.693194615993441 0 -0.599043184453037
36 | @end
37 | """)
38 | task = MpiTask([infile, outfile], MPI.COMM_WORLD)
39 | scfdrv = vlx.ScfRestrictedDriver(task.mpi_comm, task.ostream)
40 | scfdrv.conv_thresh = 1e-9
41 | scfdrv.compute(task.molecule, task.ao_basis, task.min_basis)
42 | scfdrv.task = task
43 |
44 | print(adcc.banner())
45 |
46 | # Run an adc2 calculation:
47 | state = adcc.adc2(scfdrv, n_singlets=7, conv_tol=1e-8)
48 |
49 | print()
50 | print(" st ex.ene. (au) f transition dipole moment (au)"
51 | " state dip (au)")
52 | for i, val in enumerate(state.excitation_energy):
53 | fmt = "{0:2d} {1:12.8g} {2:9.3g} [{3:9.3g}, {4:9.3g}, {5:9.3g}]"
54 | fmt += " [{6:9.3g}, {7:9.3g}, {8:9.3g}]"
55 | print(state.kind[0], fmt.format(i, val, state.oscillator_strength[i],
56 | *state.transition_dipole_moment[i],
57 | *state.state_dipole_moment[i]))
58 |
59 | # Plot a spectrum
60 | state.plot_spectrum()
61 | plt.savefig("veloxchem_ccpvdz_adc2_spectrum.pdf")
62 | plt.show()
63 |
64 | print()
65 | print(state.timer.describe())
66 |
--------------------------------------------------------------------------------
/examples/water/veloxchem_sto3g_adc2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | ## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3 | import os
4 | import tempfile
5 |
6 | from mpi4py import MPI
7 |
8 | import adcc
9 | import veloxchem as vlx
10 | from veloxchem.mpitask import MpiTask
11 |
12 | # Run SCF in VeloxChem
13 | with tempfile.TemporaryDirectory() as tmpdir:
14 | infile = os.path.join(tmpdir, "vlx.in")
15 | outfile = os.path.join(tmpdir, "/dev/null")
16 |
17 | with open(infile, "w") as fp:
18 | fp.write("""
19 | @jobs
20 | task: hf
21 | @end
22 |
23 | @method settings
24 | basis: sto-3g
25 | @end
26 |
27 | @molecule
28 | charge: 0
29 | multiplicity: 1
30 | units: bohr
31 | xyz:
32 | O 0 0 0
33 | H 0 0 1.795239827225189
34 | H 1.693194615993441 0 -0.599043184453037
35 | @end
36 | """)
37 | task = MpiTask([infile, outfile], MPI.COMM_WORLD)
38 | scfdrv = vlx.ScfRestrictedDriver(task.mpi_comm, task.ostream)
39 | scfdrv.conv_thresh = 1e-8
40 | scfdrv.compute(task.molecule, task.ao_basis, task.min_basis)
41 | scfdrv.task = task
42 |
43 | # Run an adc2 calculation:
44 | state = adcc.adc2(scfdrv, n_singlets=5)
45 | print(state.describe())
46 |
--------------------------------------------------------------------------------
/libadcc/.clang-format:
--------------------------------------------------------------------------------
1 | ## ---------------------------------------------------------------------
2 | ##
3 | ## Dummy licence header
4 | ##
5 | ## ---------------------------------------------------------------------
6 |
7 | ## DO NOT EDIT
8 | ## This file is automatically generated from a file in the repository "krims".
9 | ## Edit the original and call the script "update_from_sister_repos.sh" instead.
10 |
11 | ---
12 | Language: Cpp
13 | AccessModifierOffset: -1
14 | AlignAfterOpenBracket: Align
15 | AlignConsecutiveAssignments: true
16 | AlignConsecutiveDeclarations: false
17 | AlignEscapedNewlinesLeft: true
18 | AlignOperands: true
19 | AlignTrailingComments: true
20 | AllowAllParametersOfDeclarationOnNextLine: true
21 | AllowShortBlocksOnASingleLine: false
22 | AllowShortCaseLabelsOnASingleLine: false
23 | AllowShortFunctionsOnASingleLine: All
24 | AllowShortIfStatementsOnASingleLine: true
25 | AllowShortLoopsOnASingleLine: true
26 | AlwaysBreakAfterReturnType: None
27 | AlwaysBreakBeforeMultilineStrings: true
28 | AlwaysBreakTemplateDeclarations: true
29 | BinPackArguments: true
30 | BinPackParameters: true
31 | BraceWrapping:
32 | AfterClass: false
33 | AfterControlStatement: false
34 | AfterEnum: false
35 | AfterFunction: false
36 | AfterNamespace: false
37 | AfterObjCDeclaration: false
38 | AfterStruct: false
39 | AfterUnion: false
40 | BeforeCatch: false
41 | BeforeElse: false
42 | IndentBraces: false
43 | BreakBeforeBinaryOperators: None
44 | BreakBeforeBraces: Attach
45 | BreakBeforeTernaryOperators: true
46 | BreakConstructorInitializersBeforeComma: false
47 | ColumnLimit: 90
48 | CommentPragmas: '^ IWYU pragma:'
49 | ConstructorInitializerAllOnOneLineOrOnePerLine: true
50 | ConstructorInitializerIndentWidth: 6
51 | ContinuationIndentWidth: 6
52 | Cpp11BracedListStyle: true
53 | DerivePointerAlignment: false
54 | DisableFormat: false
55 | ExperimentalAutoDetectBinPacking: false
56 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
57 | IndentCaseLabels: true
58 | IndentWidth: 2
59 | IndentWrappedFunctionNames: false
60 | KeepEmptyLinesAtTheStartOfBlocks: true
61 | MaxEmptyLinesToKeep: 1
62 | NamespaceIndentation: None
63 | ObjCBlockIndentWidth: 2
64 | ObjCSpaceAfterProperty: false
65 | ObjCSpaceBeforeProtocolList: false
66 | PenaltyBreakBeforeFirstCallParameter: 1
67 | PenaltyBreakComment: 300
68 | PenaltyBreakFirstLessLess: 120
69 | PenaltyBreakString: 1000
70 | PenaltyExcessCharacter: 1000000
71 | PenaltyReturnTypeOnItsOwnLine: 200
72 | PointerAlignment: Left
73 | ReflowComments: true
74 | SortIncludes: true
75 | SpaceAfterCStyleCast: false
76 | SpaceBeforeAssignmentOperators: true
77 | SpaceBeforeParens: ControlStatements
78 | SpaceInEmptyParentheses: false
79 | SpacesBeforeTrailingComments: 2
80 | SpacesInAngles: false
81 | SpacesInContainerLiterals: true
82 | SpacesInCStyleCastParentheses: false
83 | SpacesInParentheses: false
84 | SpacesInSquareBrackets: false
85 | Standard: Cpp11
86 | TabWidth: 8
87 | UseTab: Never
88 | ...
89 |
90 |
--------------------------------------------------------------------------------
/libadcc/.ycm_extra_conf.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | # This file is loosely based upon the file
4 | # cpp/ycm/.ycm_extra_conf.py from the youcompleteme daemon process
5 | # available on github:
6 | # https://github.com/Valloric/ycmd/blob/master/cpp/ycm/.ycm_extra_conf.py
7 |
8 |
9 | # These are the compilation flags that will be used in case there's no
10 | # compilation database set (by default, one is not set).
11 | flags = [
12 | # Warnings: For a very detailed discussion about this
13 | # see the following stackexchange post:
14 | # https://programmers.stackexchange.com/questions/122608#124574
15 | '-Werror',
16 | '-Wall',
17 | '-Wextra',
18 | '-pedantic',
19 | "-Wnon-virtual-dtor",
20 | "-Woverloaded-virtual",
21 | "-Wshadow",
22 | "-Wold-style-cast",
23 | "-Wcast-align",
24 | "-Wconversion",
25 | "-Wuseless-cast",
26 | "-Wsign-conversion",
27 | "-Wmisleading-indentation",
28 | "-Wduplicated-cond",
29 | "-Wduplicated-branches",
30 | "-Wlogical-op",
31 | "-Wnull-dereference",
32 | "-Wdouble-promotion",
33 | "-Wformat=2",
34 | '-fexceptions', # Generate unwind information
35 | '-DDEBUG', # Compile as debug
36 | '-std=c++11', # and c++ 11
37 | '-x', 'c++', # Treat .h header files as c++
38 | # Include other libraries and show errors and
39 | # warnings within them
40 | # To suppress errors shown here, use "-isystem"
41 | # instead of "-I"
42 | '-isystem', '~/.local/include',
43 | '-isystem', '/usr/local/include',
44 | # Explicit clang includes:
45 | '-isystem', '/usr/include/c++/v1',
46 | ]
47 |
48 |
49 | DIRECTORY_OF_THIS_SCRIPT = os.path.dirname(os.path.abspath(__file__))
50 | SOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc', '.c', '.C']
51 |
52 |
53 | def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
54 | if not working_directory:
55 | return list(flags)
56 | new_flags = []
57 | make_next_absolute = False
58 | path_flags = ['-isystem', '-I', '-iquote', '--sysroot=']
59 | for flag in flags:
60 | new_flag = flag
61 |
62 | if make_next_absolute:
63 | make_next_absolute = False
64 | if not flag.startswith('/'):
65 | new_flag = os.path.join(working_directory, flag)
66 |
67 | for path_flag in path_flags:
68 | if flag == path_flag:
69 | make_next_absolute = True
70 | break
71 |
72 | if flag.startswith(path_flag):
73 | path = flag[len(path_flag):]
74 | new_flag = path_flag + os.path.join(working_directory, path)
75 | break
76 |
77 | if new_flag:
78 | new_flags.append(new_flag)
79 | return new_flags
80 |
81 |
82 | def IsHeaderFile(filename):
83 | extension = os.path.splitext(filename)[1]
84 | return extension in ['.h', '.hxx', '.hpp', '.hh']
85 |
86 |
87 | def FlagsForFile(filename, **kwargs):
88 | relative_to = DIRECTORY_OF_THIS_SCRIPT
89 | final_flags = MakeRelativePathsInFlagsAbsolute(flags, relative_to)
90 |
91 | return {
92 | 'flags': final_flags,
93 | 'do_cache': True
94 | }
95 |
--------------------------------------------------------------------------------
/libadcc/AxisInfo.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2020 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #include "AxisInfo.hh"
21 |
22 | namespace libadcc {
23 |
24 | bool operator==(const AxisInfo& lhs, const AxisInfo& rhs) {
25 | if (lhs.label != rhs.label) return false;
26 | if (lhs.n_orbs_alpha != rhs.n_orbs_alpha) return false;
27 | if (lhs.n_orbs_beta != rhs.n_orbs_beta) return false;
28 | if (lhs.block_starts != rhs.block_starts) return false;
29 | return true;
30 | }
31 |
32 | } // namespace libadcc
33 |
--------------------------------------------------------------------------------
/libadcc/AxisInfo.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2020 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include
22 | #include
23 |
24 | namespace libadcc {
25 |
26 | /** Info data structure for tensor axes */
27 | struct AxisInfo {
28 | std::string label; //!< The label for this axis
29 | size_t n_orbs_alpha; //!< The number of (alpha) orbitals
30 | size_t n_orbs_beta; //!< The number of beta orbitals (or zero for axes without spin)
31 | std::vector block_starts; //!< The split indices when a new block starts
32 |
33 | AxisInfo(std::string label_, size_t n_orbs_alpha_, size_t n_orbs_beta_ = 0,
34 | std::vector block_starts_ = {0})
35 | : label(label_),
36 | n_orbs_alpha(n_orbs_alpha_),
37 | n_orbs_beta(n_orbs_beta_),
38 | block_starts(block_starts_) {}
39 |
40 | /** Does the axis have a spin-splitting, or can no spin be identified */
41 | bool has_spin() const { return n_orbs_beta > 0; }
42 |
43 | /** Size of the axis, i.e. sum of number of alpha and beta orbitals */
44 | size_t size() const { return n_orbs_alpha + n_orbs_beta; }
45 | };
46 |
47 | bool operator==(const AxisInfo& lhs, const AxisInfo& rhs);
48 |
49 | inline bool operator!=(const AxisInfo& lhs, const AxisInfo& rhs) { return !(lhs == rhs); }
50 |
51 | } // namespace libadcc
52 |
--------------------------------------------------------------------------------
/libadcc/MoSpaces/construct_blocks.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #include "construct_blocks.hh"
21 | #include "../exceptions.hh"
22 |
23 | namespace libadcc {
24 |
25 | std::vector construct_blocks(std::vector block_starts_crude,
26 | size_t length, size_t max_block_size) {
27 | std::vector ret;
28 |
29 | // Lambda to insert extra block starts into ret. It gets the last position of a block
30 | // start and the next planned one and checks whether this is so large such that extra
31 | // starts need to be inserted. If that is the case these are inserted to ret.
32 | auto insert_extra_starts = [](std::vector& ret, size_t last_start,
33 | size_t next_start, size_t max_block_size) {
34 | const size_t len = next_start - last_start;
35 | if (len > max_block_size) {
36 | // Split into this number of blocks:
37 | const size_t n_blocks = (len + max_block_size - 1) / max_block_size;
38 |
39 | // The first few blocks might need to be a little larger to
40 | // make sure to completely tile the length len.
41 | // The block size of the small blocks
42 | const size_t block_size = len / n_blocks;
43 |
44 | // The remainder gives the number of "large blocks" we need.
45 | const size_t n_large_blocks = len % n_blocks;
46 |
47 | // The current position of block starts
48 | size_t pos = last_start;
49 | for (size_t ib = 0; ib < n_large_blocks; ++ib) {
50 | if (ib != 0) ret.push_back(pos);
51 | pos += block_size + 1;
52 | }
53 | for (size_t ib = n_large_blocks; ib < n_blocks; ++ib) {
54 | if (ib != 0) ret.push_back(pos);
55 | pos += block_size;
56 | }
57 | if (pos != next_start) {
58 | throw runtime_error("Internal error: Block tiling failed.");
59 | }
60 | }
61 | return next_start;
62 | };
63 |
64 | // Make sure at least a block start at 0 is in the block_starts_crude
65 | if (block_starts_crude.empty()) {
66 | block_starts_crude.push_back(0);
67 | }
68 | size_t last_start = block_starts_crude.front();
69 | ret.push_back(last_start);
70 | for (auto it = block_starts_crude.begin() + 1; it != block_starts_crude.end(); ++it) {
71 | last_start = insert_extra_starts(ret, last_start, *it, max_block_size);
72 | ret.push_back(*it);
73 | }
74 | insert_extra_starts(ret, last_start, length, max_block_size);
75 | return ret;
76 | }
77 |
78 | } // namespace libadcc
79 |
--------------------------------------------------------------------------------
/libadcc/MoSpaces/construct_blocks.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include
22 | #include
23 |
24 | namespace libadcc {
25 | /**
26 | * \addtogroup ReferenceObjects
27 | */
28 | ///@{
29 |
30 | /** Construct a list of Tensor blocks (by identifying their starting indices)
31 | * from a list of indices that identify places where a block definitely
32 | * has to start and a maximal block size.
33 | *
34 | * The function checks the block sizes resulting from block_starts_crude
35 | * and if they are beyond max_block_size tries to split them evenly.
36 | *
37 | * \param block_starts_crude list of crude block starts
38 | * \param length Total number of indices
39 | * \param max_block_size Maximal size of a block
40 | */
41 | std::vector construct_blocks(std::vector block_starts_crude,
42 | size_t length, size_t max_block_size);
43 |
44 | ///@}
45 | } // namespace libadcc
46 |
--------------------------------------------------------------------------------
/libadcc/MoSpaces/setup_point_group_table.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 |
22 | // Change visibility of libtensor singletons to public
23 | #pragma GCC visibility push(default)
24 | #include
25 | #pragma GCC visibility pop
26 |
27 | namespace libadcc {
28 | /**
29 | * \addtogroup TensorLibtensor
30 | */
31 | ///@{
32 |
33 | /** Setup point group symmetry table inside libtensor and return the irrep mapping as
34 | * libtensor needs it. */
35 | std::map setup_point_group_table(
36 | libtensor::product_table_container& ptc, const std::string& point_group);
37 |
38 | ///@}
39 | } // namespace libadcc
40 |
--------------------------------------------------------------------------------
/libadcc/Tensor.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2018 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #include "Tensor.hh"
21 |
22 | namespace libadcc {
23 |
24 | Tensor::Tensor(std::shared_ptr adcmem_ptr, std::vector axes)
25 | : m_size(1), m_shape(axes.size(), 0), m_axes{axes}, m_adcmem_ptr{adcmem_ptr} {
26 | for (size_t i = 0; i < axes.size(); ++i) {
27 | m_shape[i] = axes[i].size();
28 | m_size *= axes[i].size();
29 | }
30 | }
31 |
32 | std::vector Tensor::subspaces() const {
33 | std::vector ret;
34 | for (const auto& ax : axes()) {
35 | ret.push_back(ax.label);
36 | }
37 | return ret;
38 | }
39 |
40 | std::string Tensor::space() const {
41 | std::string ret = "";
42 | for (const auto& ax : axes()) ret.append(ax.label);
43 | return ret;
44 | }
45 |
46 | void Tensor::fill(scalar_type value) {
47 | const std::string alphabet = "abcdefgh";
48 | if (ndim() > alphabet.size()) {
49 | throw not_implemented_error(
50 | "zeros_like and empty_like only implemented up to tensor dimensionality 8.");
51 | }
52 | std::string mask = alphabet.substr(0, ndim());
53 | set_mask(mask, value);
54 | }
55 |
56 | std::shared_ptr Tensor::zeros_like() const {
57 | auto res = empty_like();
58 | res->fill(0.0);
59 | return res;
60 | }
61 |
62 | std::shared_ptr Tensor::ones_like() const {
63 | auto res = empty_like();
64 | res->fill(1.0);
65 | return res;
66 | }
67 |
68 | std::shared_ptr make_tensor_zero(std::shared_ptr symmetry) {
69 | auto res = make_tensor(symmetry);
70 | res->fill(0.0);
71 | return res;
72 | }
73 |
74 | } // namespace libadcc
75 |
--------------------------------------------------------------------------------
/libadcc/TensorImpl/as_bispace.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include "../AxisInfo.hh"
22 | #include
23 |
24 | // Change visibility of libtensor singletons to public
25 | #pragma GCC visibility push(default)
26 | #include
27 | #pragma GCC visibility pop
28 |
29 | namespace libadcc {
30 | /**
31 | * \addtogroup TensorLibtensor
32 | */
33 | ///@{
34 |
35 | /** Form a bispace from a list of AxisInfo representing the axes of a tensor */
36 | template
37 | libtensor::bispace as_bispace(const std::vector& axes);
38 |
39 | ///@}
40 | } // namespace libadcc
41 |
--------------------------------------------------------------------------------
/libadcc/TensorImpl/as_lt_symmetry.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include "../Symmetry.hh"
22 |
23 | // Change visibility of libtensor singletons to public
24 | #pragma GCC visibility push(default)
25 | #include // Note: This header is needed here
26 | #include
27 | #pragma GCC visibility pop
28 |
29 | namespace libadcc {
30 | /**
31 | * \addtogroup TensorLibtensor
32 | */
33 | ///@{
34 |
35 | /** Translate a adcc::Symmetry object into a shared pointer of the libtensor symmetry
36 | * object */
37 | template
38 | std::shared_ptr> as_lt_symmetry(const Symmetry& sym);
39 |
40 | ///@}
41 | } // namespace libadcc
42 |
--------------------------------------------------------------------------------
/libadcc/TensorImpl/get_block_starts.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2020 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #include "get_block_starts.hh"
21 | #include "../exceptions.hh"
22 |
23 | namespace libadcc {
24 | namespace lt = libtensor;
25 |
26 | template
27 | std::vector> get_block_starts(
28 | const libtensor::block_index_space& bis) {
29 | std::vector> ret(N);
30 |
31 | for (size_t i = 0; i < N; ++i) {
32 | const size_t dim_type = bis.get_type(i);
33 | const lt::split_points& sp = bis.get_splits(dim_type);
34 | ret[i].push_back(0);
35 | for (size_t isp = 0; isp < sp.get_num_points(); ++isp) {
36 | ret[i].push_back(sp[isp]);
37 | }
38 | }
39 | return ret;
40 | }
41 |
42 | //
43 | // Explicit instantiation
44 | //
45 |
46 | #define INSTANTIATE(DIM) \
47 | template std::vector> get_block_starts( \
48 | const libtensor::block_index_space& bis);
49 |
50 | INSTANTIATE(1)
51 | INSTANTIATE(2)
52 | INSTANTIATE(3)
53 | INSTANTIATE(4)
54 |
55 | #undef INSTANTIATE
56 |
57 | } // namespace libadcc
58 |
--------------------------------------------------------------------------------
/libadcc/TensorImpl/get_block_starts.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2020 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include "../config.hh"
22 | #include
23 |
24 | // Change visibility of libtensor singletons to public
25 | #pragma GCC visibility push(default)
26 | #include
27 | #pragma GCC visibility pop
28 |
29 | namespace libadcc {
30 | namespace lt = libtensor;
31 |
32 | /** Extract the block starts from a libtensor block-index space */
33 | template
34 | std::vector> get_block_starts(
35 | const libtensor::block_index_space& bis);
36 |
37 | /** Parse the symmetry object contained in btensor get the block starts */
38 | template
39 | std::vector> get_block_starts(lt::btensor& btensor) {
40 | lt::block_tensor_ctrl ctrl_from(btensor);
41 | return get_block_starts(ctrl_from.req_const_symmetry().get_bis());
42 | }
43 |
44 | } // namespace libadcc
45 |
--------------------------------------------------------------------------------
/libadcc/TensorImpl/instantiate_valid.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | # Generate valid IF_DIMENSIONS_MATCH_EXECUTE_CONTRACT lines for TensorImpl.cc
4 |
5 | # The maximal tensor dimensionality
6 | maxdim = 4
7 |
8 |
9 | def is_valid(n_contr_idcs, dima, dimb, dimout):
10 | return dima > 0 and dimb > 0 and \
11 | dima >= n_contr_idcs and dimb >= n_contr_idcs and dimout > 0 and \
12 | dimout + n_contr_idcs + n_contr_idcs == dima + dimb
13 |
14 |
15 | valid_combinations = []
16 | for n_contr_idcs in range(maxdim + 1):
17 | for dima in range(maxdim + 1):
18 | for dimb in range(maxdim + 1):
19 | for dimout in range(maxdim + 1):
20 | if is_valid(n_contr_idcs, dima, dimb, dimout):
21 | valid_combinations.append(
22 | (n_contr_idcs, dima, dimb, dimout)
23 | )
24 |
25 | print("//")
26 | print("// Instantiation generated from TensorImpl/instantiate_valid.py")
27 | print("//")
28 | for n_contr_idcs, dima, dimb, dimout in valid_combinations:
29 | if n_contr_idcs == 0:
30 | continue
31 | print(f"IF_DIMENSIONS_MATCH_EXECUTE_CONTRACT({n_contr_idcs}, {dima}, {dimb}) //") # noqa: E501
32 |
33 | print()
34 | print()
35 | print("//")
36 | print("// Instantiation generated from TensorImpl/instantiate_valid.py")
37 | print("//")
38 | for n_contr_idcs, dima, dimb, dimout in valid_combinations:
39 | if n_contr_idcs != 0:
40 | continue
41 | print(f"IF_DIMENSIONS_MATCH_EXECUTE_TENSORPROD({dima}, {dimb}) //")
42 |
--------------------------------------------------------------------------------
/libadcc/ThreadPool.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2018 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #include "ThreadPool.hh"
21 | #include "exceptions.hh"
22 | #include
23 |
24 | namespace libadcc {
25 | namespace {
26 | void kill_thread_pool(std::shared_ptr& holder_ptr) {
27 | if (holder_ptr == nullptr) return;
28 |
29 | auto* tp_ptr = static_cast(holder_ptr.get());
30 | tp_ptr->terminate();
31 | tp_ptr->dissociate();
32 | holder_ptr.reset();
33 | }
34 | } // namespace
35 |
36 | void ThreadPool::reinit(size_t n_running, size_t n_total) {
37 | if (n_running == 0 || n_total == 0) {
38 | throw invalid_argument("n_running and n_total need to be larger than zero.");
39 | }
40 | if (n_total < n_running) {
41 | throw invalid_argument("n_running cannot be larger than n_total.");
42 | }
43 | kill_thread_pool(m_holder_ptr);
44 |
45 | // Setup new thread pool
46 | m_holder_ptr.reset(new libutil::thread_pool(n_total, n_running));
47 | auto* tp_ptr = static_cast(m_holder_ptr.get());
48 | tp_ptr->associate();
49 |
50 | m_n_running = n_running;
51 | m_n_total = n_total;
52 | }
53 |
54 | ThreadPool::~ThreadPool() { kill_thread_pool(m_holder_ptr); }
55 | } // namespace libadcc
56 |
--------------------------------------------------------------------------------
/libadcc/ThreadPool.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2018 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include
22 |
23 | namespace libadcc {
24 | /**
25 | * \addtogroup Utilities
26 | */
27 | ///@{
28 |
29 | /** Pool managing how many threads may be used for calculations. */
30 | class ThreadPool {
31 | public:
32 | /** Initialise the thread pool.
33 | *
34 | * \param n_running The total number of running threads to employ
35 | * \param n_total The total number of worker threads to use
36 | * (Either running or ready)
37 | */
38 | ThreadPool(size_t n_running, size_t n_total) : m_holder_ptr{nullptr} {
39 | reinit(n_running, n_total);
40 | }
41 |
42 | /** Reinitialise the thread pool.
43 | *
44 | * \param n_running The total number of running threads to employ
45 | * \param n_total The total number of worker threads to use
46 | * (Either running or idle)
47 | */
48 | void reinit(size_t n_running, size_t n_total);
49 |
50 | /** Initialise a thread pool without parallelisation */
51 | ThreadPool() : ThreadPool(1, 1) {}
52 |
53 | /** Return the number of running threads. */
54 | size_t n_running() const { return m_n_running; }
55 |
56 | /** Return the total number of worker threads (running or ready) */
57 | size_t n_total() const { return m_n_total; }
58 |
59 | // Avoid copying or copy-assinging
60 | ThreadPool(const ThreadPool&) = delete;
61 | ThreadPool& operator=(const ThreadPool&) = delete;
62 |
63 | ~ThreadPool();
64 |
65 | private:
66 | // Hack to avoid the libutil data structures in the interface
67 | std::shared_ptr m_holder_ptr;
68 | size_t m_n_running;
69 | size_t m_n_total;
70 | };
71 |
72 | ///@}
73 | } // namespace libadcc
74 |
--------------------------------------------------------------------------------
/libadcc/Timer.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #include "Timer.hh"
21 | #include "exceptions.hh"
22 |
23 | namespace libadcc {
24 |
25 | double Timer::now() {
26 | using namespace std::chrono;
27 | // fix reference on first use, else just get current time point (jetzt)
28 | // and return number of seconds since the reference
29 | static auto reference = high_resolution_clock::now();
30 | const auto jetzt = high_resolution_clock::now();
31 | return duration_cast>(jetzt - reference).count();
32 | }
33 |
34 | double Timer::stop(const std::string& task) {
35 | const double end = now();
36 |
37 | auto itstart = start_times.find(task);
38 | if (itstart == start_times.end()) {
39 | throw invalid_argument("Task " + task + " not running.");
40 | }
41 | const double start = itstart->second;
42 | start_times.erase(itstart);
43 |
44 | // Add an interval if a list already exists,
45 | // else create a list with one element.
46 | auto itinter = intervals.find(task);
47 | if (itinter != intervals.end()) {
48 | itinter->second.emplace_back(start, end);
49 | } else {
50 | intervals[task] = {{start, end}};
51 | }
52 | return end - start;
53 | }
54 |
55 | void Timer::start(const std::string& task) {
56 | auto itstart = start_times.find(task);
57 | if (itstart != start_times.end()) {
58 | throw invalid_argument("Task " + task + " already running.");
59 | }
60 | start_times[task] = now();
61 | }
62 |
63 | } // namespace libadcc
64 |
--------------------------------------------------------------------------------
/libadcc/Timer.hh:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) 2019 by the adcc authors
3 | //
4 | // This file is part of adcc.
5 | //
6 | // adcc is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published
8 | // by the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // adcc is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with adcc. If not, see .
18 | //
19 |
20 | #pragma once
21 | #include
22 | #include