How do I retrieve computation results by ID?#

This tutorial introduces the basics of connecting to a QCArchive server and retrieving computation results.

When you retrieve results from QCArchive, they can be in the form of single records or a larger dataset.

A record represents a single quantum chemistry computation and contains the input details and the results. While some records represent simple computations (like a single point computation), others can encapsulate more complex workflows and multiple associated computations.

A dataset is a collection of similar records.

In this QuickStart, you’ll learn how to connect to the QCArchive Demo Server and retrieve records by their IDs. If you’d like to learn more about records, see the “How do I work with records?” tutorial.

import qcportal as ptl

Create a client object and connect to the demo server#

The PortalClient is how you interact with the server, including querying records and submitting computations.

The demo server allows for unauthenticated guest access, so no username/password is necessary to read from the server. However, you will need to log in to submit or modify computations.

# Guest access
client = ptl.PortalClient("https://qcademo.molssi.org")
WARNING: This client version is newer than the server version. This may work if the versions are close, but expect exceptions and errors if attempting things the server does not support. client version: 0.54.1.post34+ga87767a0, server version: 0.54.1

Connecting with username/password

If you have a username/password, you would include those in the client connection.

client = ptl.PortalClient("https://qcademo.molssi.org", username="YOUR_USERNAME", password="YOUR_PASSWORD")

⚠️Caution⚠️: Always handle credentials with care. Never commit sensitive information like usernames or passwords to public repositories.

Retrieving a Single Record by ID#

To retrieve a record, you can use the get_records method. You pass in the IDs of the records you would like to retrieve.

If a list of IDs is specified, then a list of records is returned. Otherwise, only a single record is returned.

record = client.get_records(1)
print(record)
<SinglepointRecord id=1 status=RecordStatusEnum.complete>

From printing the record, we see that the record with ID 1 is a single point calculation (SinglePointRecord) and that this computation is “complete” (RecordStatusEnum.complete).

Viewing Record Information#

Records have lots of features, and what they have depends on the type of record - we will only cover a few here.

For the single point calculation we retrieved, we can see information about the molecule (molecule attribute), the method, basis, etc (specification), and more.

To see information about the molecule used in the calculation, use record.molecule.

# The molecule that we computed
print(record.molecule)
Molecule(name='H2O', formula='H2O', hash='635ff91')

The information above tells us that the single point calculation was performed on a helium atom.

Molecule “hash”

The molecule hash is a unique identifier that takes atom identity, connectivity, coordinates, and fragmentation into account.

The record specification shows the program used for the calculation, as well as information about the method as basis.

# The specification (method, basis, etc)
print(record.specification)
program='psi4' driver=<SinglepointDriver.energy: 'energy'> method='hf' basis='sto-3g' keywords={} protocols=AtomicResultProtocols(wavefunction=<WavefunctionProtocolEnum.all: 'all'>, stdout=True, error_correction=ErrorCorrectionProtocol(default_policy=True, policies=None), native_files=<NativeFilesProtocolEnum.none: 'none'>)

The specification printed above tells us that this calculation was performed with the Psi4 software using the hf method and sto-3g basis set.

Retrieving Multiple Records#

The previous example showed retrieving just one record from QCArchive using the get_records method. However, more than one record at a time can be retrieved by passing a list of computation IDs to the method.

records = client.get_records([1, 2, 3])

print(f"Retrieved {len(records)} records.")
Retrieved 3 records.

Using, the information presented earlier, we can see data about each computation.

for record in records:
    print(record, record.molecule)
<SinglepointRecord id=1 status=RecordStatusEnum.complete> Molecule(name='H2O', formula='H2O', hash='635ff91')
<SinglepointRecord id=2 status=RecordStatusEnum.complete> Molecule(name='H2', formula='H2', hash='fc6d38a')
<SinglepointRecord id=3 status=RecordStatusEnum.complete> Molecule(name='H2', formula='H2', hash='df0385c')

Retrieving Records by Computation Type#

The QCArchive API also allows you to retrieve records based on the computation type. QCArchive supports different types of computations including single points, optimizations, torsion drives and more. In addition to using get_records, you can also use methods specific to the type of computation of interest. For example, to retrieve single point computations only, you can use the method get_singlepoints.

records = client.get_singlepoints([1,2])
print(records)
[SinglepointRecord(id=1, record_type='singlepoint', is_service=False, properties={'pe energy': 0.0, 'scf dipole': [0.5734967483313045, 0.5734967483328919, 0.0], 'calcinfo_nmo': 7, 'return_energy': -74.82586558254185, 'return_result': -74.82586558254185, 'calcinfo_natom': 3, 'calcinfo_nbeta': 5, 'current dipole': [0.5734967483313045, 0.5734967483328919, 0.0], 'current energy': -74.82586558254185, 'return_hessian': None, 'scf_iterations': 6, 'calcinfo_nalpha': 5, 'calcinfo_nbasis': 7, 'hf total energy': -74.82586558254185, 'hf virial ratio': 1.9955381251235869, 'return_gradient': None, 'scf_total_energy': -74.82586558254185, 'hf kinetic energy': 75.16122556657778, 'scf_dipole_moment': [0.5734967483313045, 0.5734967483328919, 0.0], 'scf_total_hessian': None, 'scf total energies': [-74.6903997149966, -74.78693027430118, -74.82523768326209, -74.82583813767224, -74.8258655152088, -74.82586557953533, -74.82586558254185], 'scf_total_gradient': None, 'dd solvation energy': 0.0, 'hf potential energy': -149.98709114911964, 'one-electron energy': -125.41099580779677, 'two-electron energy': 39.44705903779722, 'scf iteration energy': -74.82586558254185, 'pcm polarization energy': 0.0, 'scf_one_electron_energy': -125.41099580779677, 'scf_two_electron_energy': 39.44705903779722, 'current reference energy': -74.82586558254185, 'nuclear_repulsion_energy': 11.138071187457697}, extras={}, status=<RecordStatusEnum.complete: 'complete'>, manager_name='snowflake_compute-pyra-df04e41a-5973-4a4d-83f0-1b4b41b9fbe0', created_on=datetime.datetime(2024, 4, 19, 15, 14, 23, 17093, tzinfo=datetime.timezone.utc), modified_on=datetime.datetime(2024, 4, 19, 15, 14, 28, 311533, tzinfo=datetime.timezone.utc), owner_user='ben', owner_group=None, compute_history_=None, task_=None, service_=None, comments_=None, native_files_=None, specification=QCSpecification(program='psi4', driver=<SinglepointDriver.energy: 'energy'>, method='hf', basis='sto-3g', keywords={}, protocols=AtomicResultProtocols(wavefunction=<WavefunctionProtocolEnum.all: 'all'>, stdout=True, error_correction=ErrorCorrectionProtocol(default_policy=True, policies=None), native_files=<NativeFilesProtocolEnum.none: 'none'>)), molecule_id=1, molecule_=None, wavefunction_=None), SinglepointRecord(id=2, record_type='singlepoint', is_service=False, properties={'pe energy': 0.0, 'scf dipole': [0.0, 0.0, 1.1102230246251565e-15], 'calcinfo_nmo': 2, 'return_energy': -1.0660263371078118, 'return_result': -1.0660263371078118, 'calcinfo_natom': 2, 'calcinfo_nbeta': 1, 'current dipole': [0.0, 0.0, 1.1102230246251565e-15], 'current energy': -1.0660263371078118, 'return_hessian': None, 'scf_iterations': 2, 'calcinfo_nalpha': 1, 'calcinfo_nbasis': 2, 'hf total energy': -1.0660263371078118, 'hf virial ratio': 1.8375905900045388, 'return_gradient': None, 'scf_total_energy': -1.0660263371078118, 'hf kinetic energy': 1.2727296006298676, 'scf_dipole_moment': [0.0, 0.0, 1.1102230246251565e-15], 'scf_total_hessian': None, 'scf total energies': [-0.7475463060037706, -1.0660263371078118, -1.0660263371078118], 'scf_total_gradient': None, 'dd solvation energy': 0.0, 'hf potential energy': -2.3387559377376794, 'one-electron energy': -2.780438541177019, 'two-electron energy': 0.714412204069207, 'scf iteration energy': -1.0660263371078118, 'pcm polarization energy': 0.0, 'scf_one_electron_energy': -2.780438541177019, 'scf_two_electron_energy': 0.714412204069207, 'current reference energy': -1.0660263371078118, 'nuclear_repulsion_energy': 1.0}, extras={}, status=<RecordStatusEnum.complete: 'complete'>, manager_name='snowflake_compute-pyra-df04e41a-5973-4a4d-83f0-1b4b41b9fbe0', created_on=datetime.datetime(2024, 4, 19, 15, 14, 23, 17097, tzinfo=datetime.timezone.utc), modified_on=datetime.datetime(2024, 4, 19, 15, 14, 28, 323997, tzinfo=datetime.timezone.utc), owner_user='ben', owner_group=None, compute_history_=None, task_=None, service_=None, comments_=None, native_files_=None, specification=QCSpecification(program='psi4', driver=<SinglepointDriver.energy: 'energy'>, method='hf', basis='sto-3g', keywords={}, protocols=AtomicResultProtocols(wavefunction=<WavefunctionProtocolEnum.all: 'all'>, stdout=True, error_correction=ErrorCorrectionProtocol(default_policy=True, policies=None), native_files=<NativeFilesProtocolEnum.none: 'none'>)), molecule_id=2, molecule_=None, wavefunction_=None)]