Skip to content

Commit

Permalink
core intf ManyBodyCalculator to ManyBodyCore (#28)
Browse files Browse the repository at this point in the history
* move ManyBodyCalculator to ManyBodyCore

* fix up docs with Calc->Core and paper snippets

* move Core to core. make implicit deps explicit
  • Loading branch information
loriab authored May 31, 2024
1 parent c55211d commit 6f3cebf
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See [changelog in docs](docs/changelog.md).
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Full documentation is available at [https://molssi.github.io/QCManyBody/](https:

## Authors

* Asem Alenaizan, @alenaizan, original Psi4 implementations of vmfc Hessians, multi-level, and embedded point charges
* Lori A. Burns, @loriab, ManyBody QCSchema and high-level interface
* Benjamin P. Pritchard, @bennybp, core interface and QCArchive integration
* Daniel G. A. Smith, @dgasmith, original Psi4 implementations of nocp, cp, and vmfc single-level e/g/H and distributed driver integration
* Asem Alenaizan, [@alenaizan](https://github.com/alenaizan), original Psi4 implementations of vmfc Hessians, multi-level, and embedded point charges
* Lori A. Burns, [@loriab](https://github.com/loriab), ManyBody QCSchema and high-level interface
* Benjamin P. Pritchard, [@bennybp](https://github.com/bennybp), core interface and QCArchive integration
* Daniel G. A. Smith, [@dgasmith](https://github.com/dgasmith), original Psi4 implementations of nocp, cp, and vmfc single-level e/g/H and distributed driver integration
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
::: qcmanybody.ManyBodyCalculator
::: qcmanybody.ManyBodyCore

::: qcmanybody.computer.ManyBodyComputer
::: qcmanybody.ManyBodyComputer
options:
show_root_heading: true
inherited_members: true
Expand Down
23 changes: 23 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
-->


## v0.3.0 / 2024-MM-DD (Unreleased)

#### Breaking Changes

* [\#28](https://github.com/MolSSI/QCManyBody/pull/28) Intf -- low-level "core" interface renamed from
`ManyBodyCalculator` to `ManyBodyCore`. The old name will continue to work for a few months. Also, its file changed
from `manybody.py` to `core.py` but it was already a top-level import.

#### New Features

#### Enhancements

* [\#28](https://github.com/MolSSI/QCManyBody/pull/28) Intf -- high-level interface is now importable from the top level module.

#### Bug Fixes

#### Misc.

#### MUST (Unmerged)

#### WIP (Unmerged)


## v0.2.1 / 2024-05-14

#### Enhancements
Expand Down
43 changes: 23 additions & 20 deletions docs/core-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,37 @@ running the calculations.

## Using the core interface

The core interface is accessed through the [`ManyBodyCalculator`][qcmanybody.manybody.ManyBodyCalculator]
The core interface is accessed through the [`ManyBodyCore`][qcmanybody.manybody.ManyBodyCore]
class.

The first step is to create a molecule. This molecule is a
[QCElemental molecule object](https://molssi.github.io/QCElemental/model_molecule.html), and must contain fragments.
(see also: [moleule input](keywords.md#molecule))

```python
import qcmanybody as qcmb
import qcelemental as qcel
from qcelemental.models import Molecule

# Create a molecule with 3 hydrogen atoms, each as its own fragment
mol = qcel.models.Molecule(symbols=['h', 'h', 'h'],
geometry=[[0,0,0],[0,0,2],[0,0,4]],
fragments=[[0], [1], [2]])
# Create a molecule with 3 neon atoms, each as its own fragment

mol = Molecule(symbols=["ne", "ne", "ne"],
geometry=[[0,0,0], [0,0,2], [0,0,4]],
fragments=[[0], [1], [2]])
```

Next, create a `ManyBodyCalculator` object. This object is constructed using the molecule,
Next, create a `ManyBodyCore` object. This object is constructed using the molecule,
the desired BSSE correction, levels of MBE, and other options of the MBE.

```python
mbc = qcmb.ManyBodyCalculator(
molecule=mol,
bsse_type=['cp'],
levels={1: 'mp2/aug-cc-pvtz', 2: 'b3lyp/def2-svp', 3: 'hf/sto-3g'},
return_total_data=True,
supersystem_ie_only=False
)
from qcmanybody import ManyBodyCore

mbc = ManyBodyCore(molecule=mol,
bsse_type=["cp"],
levels={1: "ccsd/cc-pvtz",
2: "mp2/cc-pvdz",
3: "mp2/cc-pvdz"},
return_total_data: True,
supersystem_ie_only: False,
embedding_charges: None)
```

The `levels` option is a dictionary that specifies the n-body level as a key, then an arbitrary
Expand All @@ -52,11 +55,11 @@ map these strings to some meaningful definition of a calculation.
nbody you would like to calculate). All levels must be present even if the model chemistry
is the same for all levels.

For a complete discussion of the other options available in the `ManyBodyCalculator` object, see the
For a complete discussion of the other options available in the `ManyBodyCore` object, see the
[keywords discussion](keywords.md)
the [`ManyBodyCalculator API documentation`][qcmanybody.manybody.ManyBodyCalculator].
the [`ManyBodyCore API documentation`][qcmanybody.manybody.ManyBodyCore].

The next step is to obtain the calculations to be run from the `ManyBodyCalculator` object.
The next step is to obtain the calculations to be run from the `ManyBodyCore` object.
This is done with a python generator function `iterate_molecules` that returns
a tuple. This tuple contains

Expand All @@ -76,7 +79,7 @@ does not provide any tools for running the calculations.
### Results dictionary

The data returned from the calculations is expected to be stored in a nested dictionary.
The level is the opaque label as given from the `QCManyBodyCalculator`.
The level is the opaque label as given from the `QCManyBodyCore`.
The second level is the name of the property.

```python
Expand Down Expand Up @@ -105,4 +108,4 @@ of the MBE properties.
final_results = mbc.analyze(calculation_results)
```

For a discussion about what the results contain, see the [results documentation](results.md).
For a discussion about what the results contain, see the [results documentation](results.md).
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# QCManyBody Documentation

QCManyBody is a python package for running quantum chemistry manybody expansions and interaction calculations in a
QCManyBody is a python package for running quantum chemistry many-body expansions and interaction calculations in a
package-independent way.

## Installation
Expand Down
9 changes: 4 additions & 5 deletions docs/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ Examples:
```python
from qcelemental.models import Molecule

# Molecule with 3 hydrogen atoms, each as its own fragment
h3 = Molecule(symbols=['h', 'h', 'h'],
geometry=[[0,0,0],[0,0,2],[0,0,4]],
fragments=[[0], [1], [2]])

# Molecule with 3 neon atoms, each as its own fragment
ne3 = Molecule(symbols=["ne", "ne", "ne"],
geometry=[[0,0,0],[0,0,2],[0,0,4]],
fragments=[[0], [1], [2]])

# Water tetramer
water4 = Molecule(symbols=['o', 'h', 'h', 'o', 'h', 'h', 'o', 'h', 'h', 'o', 'h', 'h'],
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ classifiers = [
"Operating System :: MacOS",
]
dependencies = [
"numpy",
"pydantic",
"qcelemental",
"qcengine",
]
Expand Down
4 changes: 3 additions & 1 deletion qcmanybody/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from importlib.metadata import version

from .manybody import ManyBodyCalculator
from .core import ManyBodyCore
from .core import ManyBodyCore as ManyBodyCalculator # legacy alias
from .computer import ManyBodyComputer
from .models import BsseEnum
from .utils import labeler, delabeler, resize_gradient, resize_hessian

Expand Down
10 changes: 5 additions & 5 deletions qcmanybody/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from qcelemental.models import FailedOperation, Molecule, DriverEnum, ProtoModel, AtomicResult, AtomicInput
import qcengine as qcng
from qcmanybody import ManyBodyCalculator
from qcmanybody import ManyBodyCore
from qcmanybody.utils import delabeler, provenance_stamp
from qcmanybody.models import BsseEnum, ManyBodyKeywords, ManyBodyInput, ManyBodyResult, ManyBodyResultProperties

Expand Down Expand Up @@ -193,7 +193,7 @@ class ManyBodyComputer(BaseComputerQCNG):
description=ManyBodyKeywords.__fields__["supersystem_ie_only"].field_info.description,
)
task_list: Dict[str, Any] = {} #MBETaskComputers] = {}
qcmb_calculator: Optional[Any] = Field(
qcmb_core: Optional[Any] = Field(
None,
description="Low-level interface",
)
Expand Down Expand Up @@ -399,7 +399,7 @@ def from_manybodyinput(cls, input_model: ManyBodyInput, build_tasks: bool = True
specifications[mtd]["specification"]["driver"] = computer_model.driver # overrides atomic driver with mb driver
specifications[mtd]["specification"].pop("schema_name", None)

computer_model.qcmb_calculator = ManyBodyCalculator(
computer_model.qcmb_core = ManyBodyCore(
computer_model.molecule,
computer_model.bsse_type,
comp_levels,
Expand All @@ -414,7 +414,7 @@ def from_manybodyinput(cls, input_model: ManyBodyInput, build_tasks: bool = True
component_properties = {}
component_results = {}

for chem, label, imol in computer_model.qcmb_calculator.iterate_molecules():
for chem, label, imol in computer_model.qcmb_core.iterate_molecules():
inp = AtomicInput(molecule=imol, **specifications[chem]["specification"])
# inp = AtomicInput(molecule=imol, **specifications[chem]["specification"], extras={"psiapi": True}) # faster for p4

Expand Down Expand Up @@ -450,7 +450,7 @@ def from_manybodyinput(cls, input_model: ManyBodyInput, build_tasks: bool = True
# print("\n<<< (ZZ 2) QCEngine harness ManyBodyComputerQCNG.from_qcschema_ben component_properties >>>")
# pprint.pprint(component_properties, width=200)

analyze_back = computer_model.qcmb_calculator.analyze(component_properties)
analyze_back = computer_model.qcmb_core.analyze(component_properties)
analyze_back["nbody_number"] = len(component_properties)
# print("\n<<< (ZZ 3) QCEngine harness ManyBodyComputerQCNG.from_qcschema_ben analyze_back >>>")
# pprint.pprint(analyze_back, width=200)
Expand Down
2 changes: 1 addition & 1 deletion qcmanybody/manybody.py → qcmanybody/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
logger = logging.getLogger(__name__)


class ManyBodyCalculator:
class ManyBodyCore:
def __init__(
self,
molecule: Molecule,
Expand Down
2 changes: 1 addition & 1 deletion qcmanybody/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qcmanybody.manybody import Molecule
from qcelemental.models import Molecule

mol_ne2 = Molecule(
symbols=["Ne", "Ne"], fragments=[[0], [1]], geometry=[0.0, 0.0, -2.834589188186742, 0.0, 0.0, 2.834589188186742]
Expand Down
2 changes: 1 addition & 1 deletion qcmanybody/tests/test_mbe_he4_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def test_count_he4_multi(mbe_keywords, ref_count, he_tetramer, request):
mbe_model = ManyBodyInput(specification={"specification": atomic_spec, "keywords": mbe_keywords, "driver": "energy"}, molecule=he_tetramer)

ret = ManyBodyComputer.from_manybodyinput(mbe_model, build_tasks=False)
ret = ret.qcmb_calculator
ret = ret.qcmb_core

text, dcount = ret.format_calc_plan()
assert compare_recursive(ref_count["all"], dcount, atol=1.e-6)
Expand Down
5 changes: 3 additions & 2 deletions qcmanybody/tests/test_mbe_he4_singlelevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from qcelemental.testing import compare_values, compare_recursive

from qcmanybody.models import AtomicSpecification, ManyBodyKeywords, ManyBodyInput
from qcmanybody.computer import ManyBodyComputer, qcvars_to_manybodyproperties
from qcmanybody import ManyBodyComputer
from qcmanybody.computer import qcvars_to_manybodyproperties

from .addons import using

Expand Down Expand Up @@ -712,7 +713,7 @@ def test_count_he4_single(mbe_keywords, ref_count, he_tetramer):
mbe_model = ManyBodyInput(specification={"specification": atomic_spec, "keywords": mbe_keywords, "driver": "energy"}, molecule=he_tetramer)

ret = ManyBodyComputer.from_manybodyinput(mbe_model, build_tasks=False)
ret = ret.qcmb_calculator
ret = ret.qcmb_core

text, dcount = ret.format_calc_plan()
assert compare_recursive(ref_count["all"], dcount, atol=1.e-6)
Expand Down
2 changes: 1 addition & 1 deletion qcmanybody/tests/test_mbe_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# qcng: from qcengine.procedures.manybody import ManyBodyComputer
from qcmanybody.computer import ManyBodyComputer
from qcmanybody import ManyBodyCalculator
from qcmanybody import ManyBodyCalculator # test old name still operational


@pytest.fixture(scope="function")
Expand Down
2 changes: 1 addition & 1 deletion qcmanybody/tests/test_multi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from qcmanybody import ManyBodyCalculator
from qcmanybody import ManyBodyCalculator # test old name still operational
from qcmanybody.models import BsseEnum
from .common import mol_h2o_3
from .utils import load_ref_data, compare_results, load_component_data
Expand Down
4 changes: 2 additions & 2 deletions qcmanybody/tests/test_multi_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from qcmanybody import ManyBodyCalculator
from qcmanybody import ManyBodyCore
from qcmanybody.models import BsseEnum
from .common import mol_h2o_3
from .utils import load_ref_data, compare_results, load_component_data
Expand All @@ -28,6 +28,6 @@ def test_h2o_trimer_multi_ss(levels, component_file, ref_file):
component_results = load_component_data(component_file)
ref_data = load_ref_data(ref_file)

mc = ManyBodyCalculator(mol_h2o_3, [BsseEnum.cp, BsseEnum.nocp, BsseEnum.vmfc], levels, True, False, None)
mc = ManyBodyCore(mol_h2o_3, [BsseEnum.cp, BsseEnum.nocp, BsseEnum.vmfc], levels, True, False, None)
nbody_results = mc.analyze(component_results)
compare_results(nbody_results, ref_data, levels)
4 changes: 2 additions & 2 deletions qcmanybody/tests/test_single.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from qcmanybody import ManyBodyCalculator
from qcmanybody import ManyBodyCore
from qcmanybody.models import BsseEnum
from .common import mol_h2o_3
from .utils import load_ref_data, compare_results, load_component_data
Expand All @@ -25,6 +25,6 @@ def test_h2o_trimer_single(levels, component_file, ref_file):
component_results = load_component_data(component_file)
ref_data = load_ref_data(ref_file)

mc = ManyBodyCalculator(mol_h2o_3, [BsseEnum.cp, BsseEnum.nocp, BsseEnum.vmfc], levels, True, False, None)
mc = ManyBodyCore(mol_h2o_3, [BsseEnum.cp, BsseEnum.nocp, BsseEnum.vmfc], levels, True, False, None)
nbody_results = mc.analyze(component_results)
compare_results(nbody_results, ref_data, levels)
4 changes: 2 additions & 2 deletions qcmanybody/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import zstandard
from qcelemental.models import Molecule, AtomicInput

from qcmanybody import ManyBodyCalculator, delabeler
from qcmanybody import ManyBodyCore, delabeler
from qcmanybody.models import BsseEnum

_my_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -172,7 +172,7 @@ def run_qcengine(
embedding_charges: Optional[Mapping[int, list]],
):

mc = ManyBodyCalculator(molecule, bsse_type, levels, return_total_data, supersystem_ie_only, embedding_charges)
mc = ManyBodyCore(molecule, bsse_type, levels, return_total_data, supersystem_ie_only, embedding_charges)

component_results = {}

Expand Down

0 comments on commit 6f3cebf

Please sign in to comment.