Search code examples
pythongraphrdkitmolecule

How to convert molecule from graph representation to RDKit Mol


I'm working on a Python project involving molecules, and for now I have been representing molecules as graphs. I have three different numpy arrays describing each graph: a binary adjacency matrix, an array storing the atomic number of each atom in the molecule, and a matrix storing the type of bonds between atoms. i only represent heavy atoms in the graphs, so no hydrogens.

I am looking for a way to check the validity of the molecules, and I have been trying to use RDKit's SanitizeMol function to do so. Is there an easy way to convert a graph into a Mol object?

I also have functions to convert my numpy format to a Networkx graph, but I can't find any way of doing the following step (nx to RDKit).

I have been trying to use an EditablMol to build the Mol manually, but then the absence of hydrogens in the graphs causes some issues with the valence of several atoms. I'm a bit stuck, any help is appreciated.

Thanks


Solution

  • See the answer below along with the links at the bottom to nx_to_rdkit functions
    SMILES from graph