Ejemplo n.º 1
0
def get_ground_state_rdm_from_qubit_operator(
        qubit_operator: Union[str, QubitOperator], n_particles: int):
    """Diagonalize operator and compute the ground state 1- and 2-RDM

    ARGS:
        qubit_operator (Union[str, QubitOperator]): The openfermion operator to diagonalize
        n_particles (int): number of particles in the target ground state
    """
    qubit_operator = load_qubit_operator(qubit_operator)
    rdm = _get_ground_state_rdm_from_qubit_op(qubit_operator, n_particles)
    save_interaction_rdm(rdm, "rdms.json")
Ejemplo n.º 2
0
def run_psi4(
    basis,
    method,
    reference,
    geometry,
    freeze_core=False,
    charge=0,
    multiplicity=1,
    save_hamiltonian=False,
    save_rdms=False,
    n_active_extract="None",
    n_occupied_extract="None",
    freeze_core_extract=False,
    nthreads=1,
    options="None",
    wavefunction="None",
):
    os.mkdir("/app/scr")
    os.environ["PSI_SCRATCH"] = "/app/scr"

    if n_active_extract == "None":
        n_active_extract = None
    if n_occupied_extract == "None":
        n_occupied_extract = None
    if options == "None":
        options = None
    else:
        if isinstance(options, str):
            options = json.loads(options)
    if wavefunction == "None":
        wavefunction = None

    with open(geometry) as f:
        geometry = json.load(f)

    res = _run_psi4(
        geometry,
        basis=basis,
        multiplicity=multiplicity,
        charge=charge,
        method=method,
        reference=reference,
        freeze_core=freeze_core,
        save_hamiltonian=save_hamiltonian,
        save_rdms=save_rdms,
        options=options,
        n_active_extract=n_active_extract,
        n_occupied_extract=n_occupied_extract,
        freeze_core_extract=freeze_core_extract,
    )

    results = res["results"]
    results["schema"] = SCHEMA_VERSION + "-energy_calc"
    with open("energycalc-results.json", "w") as f:
        f.write(json.dumps(results, indent=2))

    hamiltonian = res.get("hamiltonian", None)
    if hamiltonian is not None:
        save_interaction_operator(hamiltonian, "hamiltonian.json")

    rdms = res.get("rdms", None)
    if rdms is not None:
        save_interaction_rdm(rdms, "rdms.json")

    with open("n_alpha.txt", "w") as f:
        f.write(str(results["n_alpha"]))

    with open("n_beta.txt", "w") as f:
        f.write(str(results["n_beta"]))

    with open("n_mo.txt", "w") as f:
        f.write(str(results["n_mo"]))

    with open("n_frozen_core.txt", "w") as f:
        f.write(str(results["n_frozen_core"]))