Пример #1
0
def insert_elements(coll):
    print("adding missing elements.")
    for z in range(1, 19):
        el = Element.from_Z(z)
        r = coll.find(filter={"formula": "{}1".format(el.symbol)})
        if r.count() == 0:
            try:
                clean_mol = Molecule([el], [[0, 0, 0]])
                xyz = XYZ(clean_mol)
                bb = BabelMolAdaptor.from_string(str(xyz), "xyz")
                pbmol = pb.Molecule(bb.openbabel_mol)
                smiles = pbmol.write("smi").split()[0]
                can = pbmol.write("can").split()[0]
                inchi = pbmol.write("inchi")
                svg = pbmol.write("svg")
                d = {"molecule": clean_mol.as_dict()}
                comp = clean_mol.composition
                d["pretty_formula"] = comp.reduced_formula
                d["formula"] = comp.formula
                d["composition"] = comp.as_dict()
                d["elements"] = list(comp.as_dict().keys())
                d["nelements"] = len(comp)
                d["charge"] = 0
                d["spin_multiplicity"] = clean_mol.spin_multiplicity
                d["smiles"] = smiles
                d["can"] = can
                d["inchi"] = inchi
                # d["names"] = get_nih_names(smiles)
                d["svg"] = svg
                d["xyz"] = str(xyz)
                d["tags"] = ["G305 test set"]
                coll.insert(d)
            except Exception as ex:
                print("Error in {}".format(el))
        elif r.count() > 1:
            print("More than 1 {} found. Removing...".format(el))
            results = list(r)
            for r in results[1:]:
                print(r["_id"])
                coll.remove({"_id": r["_id"]})
Пример #2
0
if __name__ == '__main__':
    task1 = WritelammpsInputFromGaussian()
    task2 = WritelammpsOutputTask()
    task3 = ParselammpsProperties()

    coords = []
    sp = []
    solvent_molecules_path = os.path.join(
        rubicon.__path__[0], 'workflows/test_mols/solvent_molecules')
    moleculelist = glob.glob(solvent_molecules_path + '/*.pdb')
    for filename in moleculelist:
        mol = Molecule.from_file(filename)
        for site in mol:
            coords.append([c for c in site.coords])
            sp.append(site.specie.symbol)
        mol2 = Molecule(
            sp,
            coords,
            site_properties={"mol_name": [filename[48:-4]] * len(coords)})
        fw1 = Firework([task1],
                       name='Run Lammps',
                       spec={"molecules": [mol2.as_dict()]},
                       fw_id=1)
        fw2 = Firework([task2], name='Lammps Log Parsing', fw_id=2)
        fw3 = Firework([task3], name='Lammps Properties Parser', fw_id=3)
        depen = {1: [2, 3]}
        wf = Workflow([fw1, fw2, fw3], name="LAMMPS", links_dict=depen)

        lp = LaunchPad.auto_load()
        lp.add_wf(wf)