Esempio n. 1
0
def create_molecular_graph(selected_nodes, parent=None):
    molecule = create_molecule(selected_nodes, parent)

    atom_indexes = dict((atom, i) for i, atom in enumerate(molecule.atoms))
    bonds = list(
        bond
        for bond in iter_bonds(selected_nodes)
        if bond.children[0].target in atom_indexes and bond.children[1].target in atom_indexes
    )
    pairs = [(atom_indexes[bond.children[0].target], atom_indexes[bond.children[1].target]) for bond in bonds]

    graph = MolecularGraph(pairs, molecule.numbers)
    graph.bonds = bonds
    graph.molecule = molecule
    return graph
Esempio n. 2
0
def create_molecular_graph(selected_nodes, parent=None):
    molecule = create_molecule(selected_nodes, parent)

    atom_indexes = dict((atom, i) for i, atom in enumerate(molecule.atoms))
    bonds = list(bond for bond in iter_bonds(selected_nodes)
                 if bond.children[0].target in atom_indexes
                 and bond.children[1].target in atom_indexes)
    pairs = [(
        atom_indexes[bond.children[0].target],
        atom_indexes[bond.children[1].target],
    ) for bond in bonds]

    graph = MolecularGraph(pairs, molecule.numbers)
    graph.bonds = bonds
    graph.molecule = molecule
    return graph