def compound2graph(compound): compound = compound.upper() if (compound in map_compound2graph): return map_compound2graph[compound] elif (compound.find(' + ') != -1): G = ChemGraph() G.ignore_attributes = False G.add([compound2graph(c) for c in compound.split(' + ')]) return G else: raise ChemException("Unknown compound: %s" % compound)
def hash2graph(hash, update_attributes=False): """Converts a hash string into a ChemGraph. Works only one single molecule hashes """ G_total = ChemGraph() N = 0 for (atoms, bonds) in parse_hash(hash): G = ChemGraph() G.resize(len(atoms)) for n in range(len(atoms)): for m in range(n): G.set_bond(n, m, bonds.pop(0)) for n in range(len(atoms)): (G.nodes[n], G.valences[n], G.hydrogens[n], G.charges[n], G.chirality[n]) = parse_atom(atoms[n]) if (update_attributes): G.update_attributes() G.initialize_pos() G_total.add(G) return G_total