Fragment Interaction API¶
The fragment API computes counterpoise-corrected interaction energies of
two-fragment dimers. run and Molecule are also top-level exports of
q2m3. mode="classical_only" needs only the core install.
mode="full" needs the sqd extra and Linux x86_64. See
Fragment Interaction Energy for a complete run.
Workflow¶
- q2m3.fragments.run(molecule, *, avas_labels, avas_threshold, basis='cc-pvdz', mode='full', references=None, seed=0, lucj=None, reference=None, ccsd_t_budget=None)[source]¶
Compute counterpoise-corrected interaction energies of
molecule.A dimer gives a
FragmentInteractionResult. A single molecule gives theSubsystemResultof subsystem"M". Both modes select the AVAS active spaces and, for a dimer, check their correspondence before any correlated step. Both modes compute HF and frozen-core MP2.mode="classical_only"never builds the SQD stage runner.mode="full"also runs the frozen-core CCSD(T) reference when its predicted cost fitsccsd_t_budget(defaultCCSDTBudget()), builds the active-space integrals, runs SQD for all subsystems in one child interpreter, and estimates the QPE and SQD resources. A rejected CCSD(T) leavese_ccsd_tnull with the reason.referencesholds reference files, read byimport_referenceswith the fragment id andbasisof this run, andExternalReferencerecords. They form the active-space, basis and model error terms of a dimer result.- Raises:
TypeError –
avas_labelsis not a sequence of strings,avas_thresholdis not a real number, orreferencesis a single string or path.ValueError –
modeis not"full"or"classical_only", an AVAS label is malformed or matches no AO, orreferencesis given for a single molecule.ImportError –
mode="full"and the optionalsqdbackend is missing.ReferenceImportError – A reference file violates the import format, or two references share a category.
FragmentWorkflowError – The RHF or the CCSD of a subsystem does not converge, or label resolution, the ghost guard or the preflight rejects an active space.
ActiveSpaceMismatchError – The monomer active spaces do not correspond to the dimer active space.
- Parameters:
molecule (Molecule)
avas_labels (Sequence[str])
avas_threshold (float)
basis (str)
mode (str)
references (Sequence[str | PathLike[str] | ExternalReference] | None)
seed (int)
lucj (Any)
reference (Any)
ccsd_t_budget (Any)
- Return type:
- class q2m3.fragments.Molecule(symbols, coordinates_angstrom, fragments, charges, multiplicities, name=None)[source]¶
Geometry in Angstrom, with an optional split into two fragments.
chargesandmultiplicitieshold one entry per fragment, or one entry for a single molecule (fragments is None).- Parameters:
symbols (tuple[str, ...])
coordinates_angstrom (tuple[tuple[float, float, float], ...])
fragments (tuple[tuple[int, ...], tuple[int, ...]] | None)
charges (tuple[int, ...])
multiplicities (tuple[int, ...])
name (str | None)
- classmethod from_xyz(source, *, fragments=None, charges=None, multiplicities=None, name=None)[source]¶
Build a molecule from an XYZ file path or XYZ text in Angstrom.
A string that contains no newline is read as a file path.
- Raises:
ValueError – The XYZ text is malformed, an element is unknown, the fragments are not exactly two non-empty sets that partition the atoms, the number of charges or multiplicities does not match the fragments, or a multiplicity is not 1.
- Parameters:
source (str | PathLike[str])
fragments (Sequence[Sequence[int]] | None)
charges (Sequence[int] | None)
multiplicities (Sequence[int] | None)
name (str | None)
- Return type:
- property charge: int¶
Total charge of the molecule.
- geometry_sha256()[source]¶
Lowercase hex SHA-256 of the geometry and fragment definition.
The digested bytes are compact ASCII JSON with sorted keys (
json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=True)). The payload keys aresymbols,coordinates_angstrom(lists of Pythonfloat),fragments(lists of atom indices, ornull),chargesandmultiplicities.nameis not digested.- Return type:
str
Result Contracts¶
- class q2m3.fragments.result.FragmentInteractionResult(*, schema_version='fragments.result.v1', fragment_id, mode, basis, subsystems, delta_e, references, errors, correspondence, provenance, null_reasons, warnings=())[source]¶
Counterpoise-corrected interaction energies of one fragment dimer, in Ha.
delta_emaps each layer inENERGY_LAYERSto E(AB) - E(A) - E(B), all three in the dimer basis. Null entries ofdelta_eanderrorshavenull_reasonsentries under dotted keys such asdelta_e.cascianderrors.model.- Parameters:
schema_version (str)
fragment_id (str)
mode (str)
basis (str)
subsystems (Mapping[str, SubsystemResult])
delta_e (Mapping[str, float | None])
references (tuple[ExternalReference, ...])
errors (ErrorDecomposition)
correspondence (CorrespondenceReport | None)
provenance (Mapping[str, Any])
null_reasons (Mapping[str, str])
warnings (tuple[str, ...])
- validate()[source]¶
Recompute the interaction energies and check the null reasons.
- Raises:
ValueError – The subsystems are not
AB,A,B; a classical-only result holds an SQD record, or a full result lacks one; the provenance lacks a required key; a stored interaction energy or error term differs from the recomputed one by more thanDELTA_E_TOLERANCE_HA; the model error is not the sum of the active-space and basis errors; the recorded same-basis reference source is not the one used; a reference category is unknown or repeated; or a null field has no reason.- Return type:
- class q2m3.fragments.result.SubsystemResult(*, name, real_atoms, ghost_atoms, n_ao, e_hf, e_mp2, e_ccsd_t, e_casci, e_sqd, active_space, sqd, resources, null_reasons)[source]¶
Energies and records of one subsystem:
AB,A,B, orM(one molecule).Every
Nonefield has anull_reasonsentry under its field name; a missing resource estimate usesresources.<qpe|sqd>. Each resource slot holds only an estimate from that slot’s estimator.e_sqdande_casciare derived fromsqdbypromote_sqd_energies().- Parameters:
name (Literal['AB', 'A', 'B', 'M'])
real_atoms (tuple[int, ...])
ghost_atoms (tuple[int, ...])
n_ao (int)
e_hf (float | None)
e_mp2 (float | None)
e_ccsd_t (float | None)
e_casci (float | None)
e_sqd (float | None)
active_space (ActiveSpaceRecord | None)
sqd (SQDResult | None)
resources (Mapping[str, ResourceEstimate | None])
null_reasons (Mapping[str, str])
- validate()[source]¶
Check the null reasons, the resource slots and the SQD record.
- Raises:
ValueError – A null field has no
null_reasonsentry; a resource key is notqpeorsqd; a resource slot holds something other than an estimate from that slot’s estimator;sqdis not exactly anSQDResultor fails its own validation; the active space is not the one of the SQD run; ore_sqdore_cascidiffers from the value derived fromsqd.- Return type:
References And Report¶
- q2m3.fragments.import_references(path, *, fragment_id, basis)[source]¶
Read the references of
fragment_idfrom a CSV or QCSchema JSON file.A reference whose basis equals
basis(ignoring case) is a same-basis full-space reference; any other is an external reference. Values are returned in Ha.- Raises:
ReferenceImportError – The file is neither
.csvnor.json; a CSV column is missing; a unit is notHa,kcal/molorkJ/mol; a value is not a number; no CSV row hasfragment_id; or the QCSchema record lacks a field or names another fragment.- Parameters:
path (str | PathLike[str])
fragment_id (str)
basis (str)
- Return type:
tuple[ExternalReference, …]
- class q2m3.fragments.result.ExternalReference(fragment_id, method, basis, delta_e, category)[source]¶
Imported interaction energy of one fragment dimer, in Ha.
categoryis"same_basis_full_space"whenbasisis the workflow basis and"external"otherwise.- Parameters:
fragment_id (str)
method (str)
basis (str)
delta_e (float)
category (str)
- q2m3.fragments.render_report(results, *, ks_table=None)[source]¶
Return one Markdown report for all fragment results of one call.
- Parameters:
results (Sequence[FragmentInteractionResult]) – Fragment results to report, in report order.
ks_table (Mapping[str, float] | None) – Experimental labels mapped to imported Ks values. They are listed as given.
- Raises:
ValueError – The report contains a term of
BANNED_TERMS.- Return type:
str
Exceptions¶
Typed failures raised by the fragment interaction-energy workflow.
- exception q2m3.fragments.errors.FragmentWorkflowError[source]¶
The fragment workflow cannot produce a valid result for its input.
- exception q2m3.fragments.errors.ActiveSpaceMismatchError[source]¶
Monomer active spaces do not correspond to the dimer active space.