QCElemental

repository·master·Indexed 41 days ago

https://github.com/molssi/qcelemental

Core data structures for Quantum Chemistry, providing periodic table data, physical constants (NIST CODATA), covalent and van der Waals radii, and tools for Molecule QCSchema generation, validation, and translation. Supports parsing molecules from strings or databases and translating to quantum chemistry program specifications such as NWChem, Psi4, and CFour.

Tokens
19.8K
Snippets
74
Records
107
Agent score
21%

What's inside QCElemental

  1. Use Torsion Drive models

    master
    QCElemental provides Python implementations of the MolSSI QCSchema Torsion Drive models. These models are used to represent and manage data related to torsion drive calculations (scanning a dihedral angle). The implementation is split into input models, result models, and several sub-models that define the specification, keywords, protocols, and properties of the torsion drive process.
  2. QCSchema version support across QCElemental ecosystem

    master

    The following table describes how different components in the QCElemental ecosystem handle QCSchema v1 and v2. Most components follow a "version-in-is-version-out" pattern.

    | Component | QCSchema Support |
    | :--- | :--- |
    | **QCElemental** | Offers both v1 and v2 Pydantic models (as of v0.50.0) |
    | **QCEngine** | Runs v2 internally; accepts/returns v1 or v2 (as of v0.50.0) |
    | **QCManyBody** | Offers v1 and v2 models; high-level interface is version-in-is-version-out (as of v0.6.0) |
    | **simple-dftd3/s-dftd3** | Version-in-is-version-out via `dftd3.qcschema.run_qcschema()` (as of v1.3.0) |
    | **dftd4** | Version-in-is-version-out (as of v4.1.0) |
    | **optking** | Version-in-is-version-out (as of v0.5.0) |
    | **psi4** | Runs v2 internally; accepts/returns v1 or v2 (as of v1.11.0) |
    | **xtb** | Version-in-is-version-out via `xtb.qcschema.harness.run_qcschema()` |
    | **tblite** | Version-in-is-version-out via `tblite.qcschema.run_schema()` |
    | **geomeTRIC** | Internal v1 only |
  3. How Numpy serialization works in QCSchema v2

    master

    QCSchema v2 uses a custom Array type annotation to handle Numpy arrays during serialization via model_dump():

    • mode="python": Returns a dictionary where Numpy arrays are preserved as actual Numpy arrays.
    • mode="json": Returns a dictionary where Numpy arrays are converted to lists of floats (compatible with standard JSON).

    Unlike v1, v2 serialization includes all fields by default. However, Molecule, AtomicProperties, WavefunctionProperties, OptimizationProperties, and ManyBodyProperties will still exclude None values.

    # Returns dict with numpy arrays
    data_py = model.model_dump(mode="python")
    
    # Returns dict with lists (JSON compatible)
    data_json = model.model_dump(mode="json")
  4. Use Atomic (Single-Point) models in QCElemental

    master

    QCElemental provides Python implementations of the MolSSI QCSchema for 'Atomic' or 'Single-Point' models. These models are used to represent calculations performed on single atoms. The implementation is structured around several key Pydantic models:

    • AtomicInput: Defines the input parameters for an atomic calculation.
    • AtomicResult: Defines the output data and results from an atomic calculation.
    • AtomicSpecification: A sub-model used to describe the specific requirements or setup of the atomic calculation.

    Each of these models includes a .convert_v() method to facilitate version conversion or data transformation within the schema.

  5. Pin a specific version of covalent radii data

    master

    By default, qcel.covalentradii points to the latest available data and will be updated over time. To ensure reproducibility in your workflows, you can "pin" a specific data version by creating a context object.

    Currently, the only available version is ALVAREZ2008.

    >>> context = qcel.CovalentRadii("ALVAREZ2008")
    >>> qcel.covalentradii.get(6)
    1.4361918553479494
  6. Use Torsion Drive sub-models

    master

    The Torsion Drive implementation is composed of several specialized sub-models used to structure the data:

    • TorsionDriveSpecification: Defines the technical specification of the torsion drive.
    • TorsionDriveKeywords: Contains the keywords/parameters used in the calculation.
    • TorsionDriveProtocols: Defines the protocols followed during the torsion drive.
    • TorsionDriveProperties: Captures the physical or calculated properties resulting from the torsion drive.
  7. Pin physical constants to a specific version using Contexts

    master

    Physical constants change as experimental precision improves. While qcel.constants defaults to the latest NIST data, you can "pin" your calculations to a specific historical version to ensure reproducibility.

    Currently, only CODATA2014 is available via the qcel.PhysicalConstantsContext class.

    import qcelemental as qcel
    
    # Create a context pinned to CODATA 2014
    context = qcel.PhysicalConstantsContext("CODATA2014")
    
    # Use the context to perform conversions
    factor = context.conversion_factor("hartree", "eV")
  8. Pin a specific van der Waals Radii context version

    master

    To ensure reproducibility and prevent your results from changing when the default data is updated, you can "pin" a specific version of the van der Waals radii data by creating a specific context object.

    Currently, the only available context is MANTINA2009.

    >>> context = qcel.VanderWaalsRadii("MANTINA2009")
    >>> # Use the context object to retrieve data
    >>> context.get(6)
    3.212534413278308
  9. Access periodic table data via aliases

    master

    QCElemental's periodic table API allows you to retrieve chemical properties using multiple types of aliases. You can pass an atomic number (int), a chemical symbol (str), an isotope symbol (str), or a chemical name (str) to the property functions. The API will resolve these aliases to the correct quantity.

    # All these aliases resolve to the same mass
    qcel.periodictable.to_mass(6)        # Atomic number
    qcel.periodictable.to_mass("C")      # Symbol
    qcel.periodictable.to_mass("C12")    # Isotope symbol
    qcel.periodictable.to_mass("Carbon") # Name
  10. How to run comparisons against Psi4 and Cfour data

    master

    The qcelemental/checkup_data directory contains periodic table and physical constant data sourced from Psi4 and Cfour. This data is used to validate qcelemental outputs by running comparisons via the PeriodicTable.run_comparison() method.

    Note: This directory is intended for data storage and is usually not imported directly into your code.

    # Example conceptual usage for running comparisons
    PeriodicTable.run_comparison()
  11. Understand the difference between QCSchema v1 and v2

    master

    Starting with QCElemental v0.50.0, QCSchema v2 is available. It is a technical upgrade to Pydantic v2 and does not introduce new features, but it rearranges fields to make models more composable and distinguishable in dictionary form.

    FeatureQCSchema v1QCSchema v2
    Pydantic Basepydantic.v1.BaseModelpydantic.BaseModel
    Molecule schema_version23
    Import Pathqcelemental.models.v1qcelemental.models.v2
    QCElemental Baseqcelemental.models.v1.ProtoModelqcelemental.models.v2.ProtoModel

    Timeline:

    • v0.50: v2 available; v1 unchanged.
    • v0.60: v2 layout finalized.
    • v0.70: v2 becomes default; v1 requires specific import paths.
    • v1.0: v1 dropped.
  12. How to migrate between QCSchema v1 and v2

    master

    Because Pydantic does not allow nesting v1 and v2 models, you should overhaul QCSchema operations all at once.

    Recommended Pattern for Library Authors: To support both versions, convert to v2 internally and handle v1/v2 at the interface level:

    1. Accept a v1 or v2 object.
    2. Convert it to v2 using .convert_v(2).
    3. Perform all internal logic using v2 models.
    4. Convert back to the requested version using .convert_v(return_version) before returning control to the caller.

    Testing: Use the schema_versions pytest fixtures to parametrize your tests for both v1 and v2 simultaneously.

    # Convert a v1 model to v2
    v2_model = v1_model.convert_v(2)
    
    # Convert back to v1
    v1_model = v2_model.convert_v(1)