def load():
    
    import qcfractal.interface as ptl

    NAME = "QCA"
    # this builds the index, starting with the client node
    NAMEP = NAME + ".p"
    if os.path.exists( NAMEP ):
        with open( NAMEP, 'rb') as fid:
            QCA = pickle.load( fid)
        if QCA.db is None:
            with open( NAME + ".db.p", 'rb') as fid:
                QCA.db = pickle.load( fid).db

    else:

        client = ptl.FractalClient()
        client_node = Node.Node( payload=client, name="client")
        QCA = qca.QCATree( NAME, root_payload=client, node_index=None, db=None )

        DS_NAME = "OpenFF Trivalent Nitrogen Set 1"
        DS_NAME = "SMIRNOFF Coverage Torsion Set 1"

        DS_TYPE = "TorsionDriveDataset"
        DS_NAME = "OpenFF Gen 2 Torsion Set 2 Coverage"
        client.get_collection( DS_TYPE, DS_NAME)
        ds = client.get_collection( DS_TYPE, DS_NAME)

        drop=[]
        # since we know there are no Hessians, skip looking for them
        #drop.append("Hessian")
        QCA.build_index( ds, drop=drop)

        DS_TYPE = "OptimizationDataset"
        DS_NAME = "OpenFF Gen 2 Opt Set 2 Coverage"
        ds = client.get_collection( DS_TYPE, DS_NAME)
        QCA.build_index( ds, drop=drop)

        # this will download the final structure of *all* minimizations found
        # for a gridopt, this will just be the final structure of each point
        QCA.cache_optimization_minimum_molecules()

        # save the index and data to disk for future analysis
        QCA.to_pickle( db=False)
        QCA.to_pickle( name=QCA.name + ".db.p", index=False, db=True)

    return QCA
if False:

    # TODO: needs work still as ui can't be imported
    # Load a list of datasets and build the index
    # "datasets" is a file of datasets to load
    datasets = offsb.ui.qcasb.load_dataset_input("datasets")

    QCA = offsb.ui.qcasb.QCArchiveSpellBook(datasets=datasets).QCA

else:
    # Just a quick shortcut to get something going
    client = ptl.FractalClient()
    ds = client.get_collection("TorsionDriveDataset",
                               "OpenFF Gen 2 Torsion Set 1 Roche")
    QCA = QCA = qca.QCATree("QCA",
                            root_payload=client,
                            node_index=dict(),
                            db=dict())
    drop = ["Intermediates", "Hessian"]

    QCA.build_index(ds, drop=drop, keep_specs=["default"])
    save(QCA)

entries = list(QCA.node_iter_depth_first(QCA.root(), select="Entry"))
print("There are {:d} entries total".format(len(entries)))

# The general query on the dataset.
# The results respect the key, and will only return those indices if specified
# If no key is specified, then the indices are in order as they appear in the string
query = smiles.SmilesSearchTree("[#7X3:2](~[#1:1])(~[#6])~[#6:3]=[O:4]",
                                QCA,
                                name="smiles")
Example #3
0
def generate_status_report( collection, name, logname):
    """
    Iterates a dataset, checking for errors, and saves errors to the log file.
    """

    client = ptl.FractalClient()
    QCA = qca.QCATree( "QCA", root_payload=client, node_index=dict(), db=dict())
    for s in sets:
        ds = client.get_collection( collection, name)
        QCA.build_index( ds, drop=["Gradient"], keep_specs=["default"],
            start=0, limit=0)

    default = [n for n in QCA.node_iter_depth_first(QCA.root()) 
        if "QCS-default" in n.payload]
    mindepth = QCA.node_depth(default[0])
    tdfailures= 0

    fid = open(logname, 'w')

    for node in QCA.node_iter_dive(default):
        i = QCA.node_depth(node) - mindepth+1
        status=""
        statbar= "    "
        errmsg = ""
        hasstat = False
        qcp = QCA.db[node.payload]['data']
        try:
            hasstat = "status" in QCA.db[node.payload]["data"]
        except Exception:
            pass
        if hasstat:
            status = qcp["status"][:]
            if status != "COMPLETE" and node.name == "Optimization":
                try:
                    statbar = "----"
                    client = qcp['client']
                    print("error", qcp['error'], qcp['error'] is None)
                    if not (qcp['error'] is None):
                        key=int(qcp['error'])
                        err = list(client.query_kvstore(key).values())[0]
                        errmsg += "####ERROR####\n"
                        errmsg += "Error type: " + err['error_type'] + "\n"
                        errmsg += "Error:\n" + err['error_message']
                        errmsg += "############\n"
                    elif status == "ERROR":
                        errmsg += "####FATAL####\n"
                        errmsg += "Job errored and no error on record. "
                        errmsg += "Input likely bogus; check your settings\n"
                        errmsg += "############\n"
                    if not (qcp['stdout'] is None):
                        key=int(qcp['stdout'])
                        msg = list(client.query_kvstore(key)).values())[0]
                        errmsg += "----ISSUE----\n"
                        errmsg += "Status was not complete; stdout is:\n"
                        errmsg += msg
                        errmsg += "-------------\n"
                    if not (qcp['stderr'] is None):
                        key=int(qcp['stderr'])
                        msg = list(client.query_kvstore(key)).values())[0]
                        errmsg += "####ISSUE####\n"
                        errmsg += "Status was not complete; stderr is:\n"
                        errmsg += msg
                        errmsg += "-------------\n"
                except Exception as e:
                    fid.write("Internal issue:\n" + str(e) + '\n')

            if status != "COMPLETE" and node.name == "TorsionDrive":
                statbar = "XXXX"
        if node.name == "TorsionDrive" and status != "COMPLETE":
            tdfailures += 1
        fid.write("{:2d} {} {} {}\n".format(tdi,statbar*i,
            " ".join([str(node.index),str(node.name), str(node.payload)]),
            status))
        if errmsg != "":
            fid.write("\n{}\n".format(errmsg))