def test_makeopenbabel(self): import openbabel atomnos = numpy.array([1, 8, 1], "i") atomcoords = numpy.array([[[-1., 1., 0.], [0., 0., 0.], [1., 1., 0.]]]) obmol = cclib2openbabel.makeopenbabel(atomcoords, atomnos) obconversion = openbabel.OBConversion() formatok = obconversion.SetOutFormat("inchi") assert obconversion.WriteString(obmol).strip() == "InChI=1S/H2O/h1H2"
def test_makeopenbabel_and_makecclib(self): """Ensure that makeopenbabel and makecclib are inverse of each other""" atomnos = numpy.array([1, 8, 1], "i") atomcoords = numpy.array([[[-1., 1., 0.], [0., 0., 0.], [1., 1., 0.]]]) # makecclib(makeopenbabel(...)) obmol = cclib2openbabel.makeopenbabel(atomcoords, atomnos) data = cclib2openbabel.makecclib(obmol) numpy.testing.assert_allclose(data.atomcoords, atomcoords) numpy.testing.assert_allclose(data.atomnos, atomnos) # makeopenbabel(makecclib(...)) obmol = cclib2openbabel.makeopenbabel(data.atomcoords, data.atomnos) data = cclib2openbabel.makecclib( obmol) # this line is just to make the test easier numpy.testing.assert_allclose(data.atomcoords, atomcoords) numpy.testing.assert_allclose(data.atomnos, atomnos)
def get_InChI(attr): try: params = { "atomcoords": np.asarray(attr["atomcoords"]), "atomnos": attr["atomnos"], "charge": attr["charge"], "mult": attr["mult"] } mol = makeopenbabel(**params) obconversion = ob.OBConversion() obconversion.SetOutFormat("inchi") ob.obErrorLog.StopLogging() inchi = obconversion.WriteString(mol).strip() if inchi.startswith("InChI="): inchi = inchi.replace("InChI=", "") return inchi except: return None
def generate_svg(res, inserted_id): dir_path = "flaskapp/static/svg/" if not os.path.isdir(dir_path): os.mkdir(dir_path) try: params = { "atomcoords": np.asarray(res["atomcoords"]), "atomnos": np.asarray(res["atomnos"]), "charge": res["charge"], "mult": res["mult"] } except: pass try: # Save the SVG file with filename same as mongodb document id file_path = dir_path + inserted_id + ".svg" print("Creating SVG : " + file_path) mol = makeopenbabel(**params) obconversion = ob.OBConversion() obconversion.SetOutFormat("svg") ob.obErrorLog.StopLogging() obconversion.WriteFile(mol, file_path) except: pass