def bonds2graph(bonds): graph = ChemGraph() n = 0 m = 0 graph.add_node(atom_wildcard) for b in bonds: if (m == n): graph.add_node(atom_wildcard) m = 0 n += 1 graph.set_bond(n, m, b) m += 1 if (m != n): raise ChemException("length of bonds list is not N(N-1)/2: " + str(bonds)) return graph
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