Inputs
Data structures for specifying quantum chemistry calculations. The most commonly used structure is a ProgramInput which defines a single calculation.
The hierarchy is Files → FileInput → ProgramSpec → ProgramInput. Every input requires program, the requested executor; ProgramOutput.results.provenance.program records the program that actually produced the result.
ProgramSpec describes a calculation without structures. It has its own program, calctype, optional model, keywords, files, cmdline_args, extras, and recursive subprograms. Model remains a distinct scientific concept with method and basis. A program without a meaningful model, such as an optimizer, can leave model=None.
from qcdata import CalcType, ProgramInput, ProgramSpec, Structure
input_data = ProgramInput(
program="geometric",
calctype="optimization",
structure=Structure.open("structure.xyz"),
keywords={"maxiter": 250},
subprograms=[
ProgramSpec(
program="terachem",
calctype="gradient",
model={"method": "wb97x-d3", "basis": "def2-svp"},
keywords={"convthre": 1e-6},
),
],
)
gradient_spec = input_data.get_subprogram(CalcType.gradient)
Children can contain further subprograms to arbitrary depth. Each immediate child must have a unique CalcType among its siblings. get_subprogram(calctype) accepts a CalcType or its string value (for example, CalcType.gradient or "gradient"), searches immediate children only, and raises ValueError if missing.
Inputs is FileInput | ProgramInput. Use ProgramInput directly for structured inputs. A ProgramSpec alone is not a top-level input because it lacks structures. Use structure for the constructor argument and attribute; the former molecule API has been removed.
This replaces ProgramArgs, ProgramArgsSub, and DualProgramInput without compatibility aliases. Migrate subprogram and subprogram_args to a subprograms list with an explicit program and calctype on each child. Existing serialized inputs also need these fields. QCSchema AtomicInput conversion requires a non-None model and raises ValueError otherwise.
ProgramInput.structure is the primary/start/reference structure for the calculation. Calculations that require additional complete structures can provide them by role name with ProgramInput.structures, for example structures={"environment": mm_region}. A role may also hold an ordered list of structures. Calculation-specific tools should validate which structure names are required.
A path optimization (calctype="path_optimization": NEB, string, growing string) is about a chain rather than one structure. Its structures, endpoints included and in order, go in structures["initial_chain"], and structure is left out:
ProgramInput(
program="...",
calctype="path_optimization",
structures={"initial_chain": [reactant, *images, product]}, # or [reactant, product]
)
Validation enforces this by calculation type: a path optimization needs a chain of at least two structures with the same atoms and no structure; every other calculation type requires structure. Code that needs one structure calls inp.require_structure(), which returns a Structure (or raises for a chain input) so type checkers know it is not None; inp.initial_chain returns the chain. To restart from a previous path, pass structures={"initial_chain": output.results.final_path.structures}.
FileInput.from_directory("inputs", program="psi4") collects native input files with the required executor identity.
A FileInput is an escape hatch that allows you to run any calculation in any QC program (or any program for that matter), even if it isn't a supported CalcType in qcdata yet. You can use a FileInput to store the native input files (text and binary) for a QC program along with the relevant command line args. Using qcop you can submit a FileInput to a QC program and all output files and logs produced by that program will be collected and returned in a user-friendly ProgramOutput object. FileInput allows you to continue to use qcdata even for calculations that haven't yet been standardized.
qcdata.ProgramInput
¶
A program specification bound to structures.
Most calculations are about one structure, structure. A path optimization is
about a chain: its structures, endpoints included and in order, go in
structures["initial_chain"] and structure is left out. Validation enforces
this by calculation type, so structure is always set for every other one; use
require_structure() where a type checker needs to know that.
Attributes:
| Name | Type | Description |
|---|---|---|
structure |
Structure | None
|
The primary/start/reference structure; None only for chain
calculation types ( |
structures |
dict[str, Structure | list[Structure]]
|
Additional complete structures identified by role, such as a
QM/MM environment, or a list of structures for a role that holds several
in order, such as |
Example
from qcdata import ProgramInput, ProgramSpec, Structure
prog_input = ProgramInput(
program="geometric",
calctype="optimization",
structure=Structure.open("structure.xyz"),
keywords={"maxiter": 250},
subprograms=[
ProgramSpec(
program="terachem",
calctype="gradient",
model={"method": "wb97x-d3", "basis": "def2-svp"},
),
],
)
get_subprogram
¶
get_subprogram(calctype: CalcType | str) -> ProgramSpec
Return an immediate child by CalcType or string value.
Raises ValueError if no matching immediate child exists.
Source code in src/qcdata/models/inputs.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
add_file
¶
add_file(
filepath: Path | str, relative_dir: Path | None = None
) -> None
Add a file to the object.
The file is added to the files attribute with the filename as the key and
the file data as the value. UTF-8 decodable files are stored as str; all
other files are stored as bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | str
|
The path to the file. |
required |
relative_dir
|
Path | None
|
The directory to make the file relative to. Helpful when adding files from a subdirectory. |
None
|
Example
my_obj.add_file("path/to/file.txt")
print(my_obj.files)
# Output: {"file.txt": "file data"}
Source code in src/qcdata/models/base_models.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
add_files
¶
add_files(
directory: StrOrPath,
recursive: bool = False,
exclude: list[str] | None = None,
) -> None
Add all files in a directory to the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
StrOrPath
|
The directory to add files from. |
required |
recursive
|
bool
|
Whether to recursively add files from subdirectories. |
False
|
exclude
|
list[str] | None
|
A list of filenames to exclude from the directory. |
None
|
Source code in src/qcdata/models/base_models.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
save_files
¶
save_files(directory: StrOrPath = Path('.')) -> None
Write all files to the specified directory.
Text data is written in text mode and binary data in binary mode. Parent directories are created for filenames that contain relative paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
StrOrPath
|
The directory to write the files to. Created if it does not exist (its parent must already exist). Defaults to the current working directory. |
Path('.')
|
Source code in src/qcdata/models/base_models.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
qcdata.ProgramSpec
¶
A recursive program specification, independent of structures.
Each child describes its own calculation. Siblings must have distinct calculation types; the same calculation type may appear at different levels of the tree.
Attributes:
| Name | Type | Description |
|---|---|---|
program |
str
|
The requested executor (distinct from result data provenance). |
calctype |
CalcType
|
The type of calculation to perform. |
model |
Model | None
|
The scientific model, or None for programs without one. |
keywords |
dict[str, Any]
|
Program keywords, excluding model and calculation type. |
subprograms |
list[ProgramSpec]
|
Child specifications, with one child per calculation type. |
files |
dict[str, str | bytes]
|
Native input files for this program. |
cmdline_args |
list[str]
|
Command line arguments for this program. |
extras |
dict[str, Any]
|
Additional information to bundle with this specification. |
get_subprogram
¶
get_subprogram(calctype: CalcType | str) -> ProgramSpec
Return an immediate child by CalcType or string value.
Raises ValueError if no matching immediate child exists.
Source code in src/qcdata/models/inputs.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
add_file
¶
add_file(
filepath: Path | str, relative_dir: Path | None = None
) -> None
Add a file to the object.
The file is added to the files attribute with the filename as the key and
the file data as the value. UTF-8 decodable files are stored as str; all
other files are stored as bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | str
|
The path to the file. |
required |
relative_dir
|
Path | None
|
The directory to make the file relative to. Helpful when adding files from a subdirectory. |
None
|
Example
my_obj.add_file("path/to/file.txt")
print(my_obj.files)
# Output: {"file.txt": "file data"}
Source code in src/qcdata/models/base_models.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
add_files
¶
add_files(
directory: StrOrPath,
recursive: bool = False,
exclude: list[str] | None = None,
) -> None
Add all files in a directory to the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
StrOrPath
|
The directory to add files from. |
required |
recursive
|
bool
|
Whether to recursively add files from subdirectories. |
False
|
exclude
|
list[str] | None
|
A list of filenames to exclude from the directory. |
None
|
Source code in src/qcdata/models/base_models.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
save_files
¶
save_files(directory: StrOrPath = Path('.')) -> None
Write all files to the specified directory.
Text data is written in text mode and binary data in binary mode. Parent directories are created for filenames that contain relative paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
StrOrPath
|
The directory to write the files to. Created if it does not exist (its parent must already exist). Defaults to the current working directory. |
Path('.')
|
Source code in src/qcdata/models/base_models.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
qcdata.FileInput
¶
File and command line argument inputs for a calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
program |
str
|
The requested executor for the calculation. |
files |
Files
|
A dict mapping filename to str or bytes data. |
cmdline_args |
list[str]
|
A list of command line arguments to be passed to the program. |
extras |
Dict[str, Any]
|
Additional information to bundle with the object. Use for schema development and scratch space. |
add_file
¶
add_file(
filepath: Path | str, relative_dir: Path | None = None
) -> None
Add a file to the object.
The file is added to the files attribute with the filename as the key and
the file data as the value. UTF-8 decodable files are stored as str; all
other files are stored as bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | str
|
The path to the file. |
required |
relative_dir
|
Path | None
|
The directory to make the file relative to. Helpful when adding files from a subdirectory. |
None
|
Example
my_obj.add_file("path/to/file.txt")
print(my_obj.files)
# Output: {"file.txt": "file data"}
Source code in src/qcdata/models/base_models.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
add_files
¶
add_files(
directory: StrOrPath,
recursive: bool = False,
exclude: list[str] | None = None,
) -> None
Add all files in a directory to the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
StrOrPath
|
The directory to add files from. |
required |
recursive
|
bool
|
Whether to recursively add files from subdirectories. |
False
|
exclude
|
list[str] | None
|
A list of filenames to exclude from the directory. |
None
|
Source code in src/qcdata/models/base_models.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
save_files
¶
save_files(directory: StrOrPath = Path('.')) -> None
Write all files to the specified directory.
Text data is written in text mode and binary data in binary mode. Parent directories are created for filenames that contain relative paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
StrOrPath
|
The directory to write the files to. Created if it does not exist (its parent must already exist). Defaults to the current working directory. |
Path('.')
|
Source code in src/qcdata/models/base_models.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
from_directory
classmethod
¶
from_directory(
directory: Path | str, **kwargs: Any
) -> Self
Collect directory files, passing required program and other fields as kwargs.
Source code in src/qcdata/models/inputs.py
40 41 42 43 44 45 46 | |
Binding a specification to structures¶
input_data = ProgramInput.from_spec(
spec, structure, structures={"reference": reference_structure}
)
This validates a new input while preserving all specification fields and recursive children. The original specification is unchanged. Additional structures are optional and are supplied explicitly when binding.