Skip to main content

volcengine-qcclient

A Python client for volcano engine quantum chemistry service.

Installation

pip install volcengine-qcclient

Usage

High-level SDK.

  1. run GPU4PySCF tasks.
import os
import requests
import h5py
import tarfile

from volcengine_qcclient import QcBatchJob


# download_output download output of qc task to ./{task_id}/ dir.
def download_output(url, task_id):
    os.mkdir(f"./{task_id}")
    if ".h5" in url:
        output_h5 = f"./{task_id}/output.h5"
        open(output_h5, 'wb').write(requests.get(url).content)
    elif "tar.gz" in url:
        output_targz = f"./{task_id}/output.tar.gz"
        open(output_targz, 'wb').write(requests.get(url).content)
        with tarfile.open(output_targz, 'r:gz') as tar:
            tar.extractall(path=f"./{task_id}")
        os.remove(output_targz)
    else:
        print("unsupported file type")


if __name__ == '__main__':
    # init batch_job
    batch_job = QcBatchJob()

    # load molecules.
    molecules = [
        '''
3
Water molecule
O          0.00000        0.00000        0.11779
H          0.00000        0.75545       -0.47116
H          0.00000       -0.75545       -0.47116
        '''
    ]

    batch_job.load_molecules(from_list=molecules)

    # set task config.
    task_config = {
        "spin": 0,
        "charge": 0,
        "basis": "def2-tzvpp",
    }
    # submit task.
    task_type = "sp"
    task_ids = batch_job.submit(task_type=task_type, task_config=task_config)
    print(task_ids)

    # wait for task to finish.
    batch_job.wait()

    # get tasks when batch_job finished.
    tasks = batch_job.get_tasks()
    print(tasks)

    # download output to ./{task_id}/
    task = tasks[0]
    download_output(task["OutputUrl"], task["Id"])

    # operation with output.
    if task_type in ["sp", "opt"]:
        with h5py.File(f"./{task['Id']}/output.h5", 'r') as f:
            print(f.keys())
    elif task_type == "pysisyphus":
        # print keys in `final_hessian.h5`.
        with h5py.File(f"./{task['Id']}/final_hessian.h5", 'r') as f:
            print(f.keys())

        # print keys in `optimization.h5`
        with h5py.File(f"./{task['Id']}/final_hessian.h5", 'r') as f:
            print(f.keys())

        # print final_geometry.xyz
        with open(f"./{task['Id']}/final_geometry.xyz", 'r') as f:
            print(f.read())

To verify the correctness of the task_config, tasks can be run locally using the command:

python -m volcengine_qcclient.drivers.sp_driver config_example.json

The task_config is specified in a config file

{
  "molecule": "h2o.xyz"
  "spin": 0,
  "charge": 0,
  "basis": "def2-tzvpp",
}

The molecular geometry is saved in the file specified by the field molecule, which is h2o.xyz in this example:

3
Water molecule
O          0.00000        0.00000        0.11779
H          0.00000        0.75545       -0.47116
H          0.00000       -0.75545       -0.47116

When the local verification is passed, the same task_config specification can be used in the QcBatchJob, while the geometries should be specified in a list and passed to the QcBatchJob.

  1. run pysisyphus tasks.
import os
import requests
import h5py
import tarfile

from volcengine_qcclient import QcBatchJob


# download_output download output of qc task to ./{task_id}/ dir.
def download_output(url, task_id):
    os.mkdir(f"./{task_id}")
    if ".h5" in url:
        output_h5 = f"./{task_id}/output.h5"
        open(output_h5, 'wb').write(requests.get(url).content)
    elif "tar.gz" in url:
        output_targz = f"./{task_id}/output.tar.gz"
        open(output_targz, 'wb').write(requests.get(url).content)
        with tarfile.open(output_targz, 'r:gz') as tar:
            tar.extractall(path=f"./{task_id}")
        os.remove(output_targz)
    else:
        print("unsupported file type")


if __name__ == '__main__':
    # init batch_job
    batch_job = QcBatchJob()

    # load molecules.
    molecules = [
        '''
3
Water molecule
O          0.00000        0.00000        0.11779
H          0.00000        0.75545       -0.47116
H          0.00000       -0.75545       -0.47116
        '''
    ]

    batch_job.load_molecules(from_list=molecules)

    # set task config.
    task_config = {}
    # submit task.
    task_type = "pysisyphus"
    task_ids = batch_job.submit(task_type=task_type, task_config=task_config)
    print(task_ids)

    # wait for task to finish.
    batch_job.wait()

    # get tasks when batch_job finished.
    tasks = batch_job.get_tasks()
    print(tasks)

    # download output to ./{task_id}/
    task = tasks[0]
    download_output(task["OutputUrl"], task["Id"])

    # operation with output.
    if task_type in ["sp", "opt"]:
        with h5py.File(f"./{task['Id']}/output.h5", 'r') as f:
            print(f.keys())
    elif task_type == "pysisyphus":
        # print keys in `final_hessian.h5`.
        with h5py.File(f"./{task['Id']}/final_hessian.h5", 'r') as f:
            print(f.keys())

        # print keys in `optimization.h5`
        with h5py.File(f"./{task['Id']}/final_hessian.h5", 'r') as f:
            print(f.keys())

        # print final_geometry.xyz
        with open(f"./{task['Id']}/final_geometry.xyz", 'r') as f:
            print(f.read())
  1. run pygsm tasks.
import os
import requests
import tarfile

from volcengine_qcclient import QcBatchJob

def download_output(url, task_id):
    os.mkdir(f"./{task_id}")
    output_targz = f"./{task_id}/output.tar.gz"
    open(output_targz, 'wb').write(requests.get(url).content)
    with tarfile.open(output_targz, 'r:gz') as tar:
        tar.extractall(path=f"./{task_id}")
    os.remove(output_targz)


if __name__ == '__main__':
    batch_job = QcBatchJob()

    # For pygsm, the xyz file may contain multiple frames (reactant/product).
    molecules = [
        '''
3

   H          0.00000000      0.00000000     1.5       
   F          0.00000000      0.00000000    -0.6
   H          0.00000000      0.00000000    -1.5
3

   H          0.00000000      0.00000000     1.5       
   F          0.00000000      0.00000000     0.6
   H          0.00000000      0.00000000    -1.5 
        '''
    ]

    batch_job.load_molecules(from_list=molecules)

    task_type = 'pygsm'
    task_config = [ {"charge": 0, "multiplicity": 2}]
    task_ids = batch_job.submit(task_type=task_type, task_config=task_config)
    print(task_ids)
    
    batch_job.wait()
    tasks = batch_job.get_tasks()
    task = tasks[0]

    download_output(task['OutputUrl'], task['Id'])
    print(f"Downloaded output to ./{task['Id']}/")

Low level SDK:

see low-level.md

Credentials

Environment variables

Metadata

Release files for volcengine-qcclient 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for volcengine-qcclient 0.2.5
File Interpreter ABI Platform Actions
volcengine_qcclient-0.2.5-py3-none-any.whl Python 3 none any Details for volcengine_qcclient-0.2.5-py3-none-any.whl

Release files / volcengine_qcclient-0.2.5-py3-none-any.whl

Download URL volcengine_qcclient-0.2.5-py3-none-any.whl
Size 73.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e21324f0e2a53bd1f17894e8cfa25eef5abdbdd516b13d9b1887849df7445dc
BLAKE2b-256 checksum
How to use checksums
c4dffe0cd521c37236965721656216551b6cd1b5f4883c5add7391541deefa1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.13

Security for volcengine-qcclient 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page