Skip to content

Instantly share code, notes, and snippets.

@daenuprobst
Created January 10, 2026 00:15
Show Gist options
  • Select an option

  • Save daenuprobst/9df8fe18a6bb06cca2a3adbed9f7c777 to your computer and use it in GitHub Desktop.

Select an option

Save daenuprobst/9df8fe18a6bb06cca2a3adbed9f7c777 to your computer and use it in GitHub Desktop.
import networkx as nx
def mol_to_nx(self, mol):
G = nx.Graph()
for atom in mol.GetAtoms():
G.add_node(
atom.GetIdx(), atom_type=atom.GetAtomicNum()
)
for bond in mol.GetBonds():
G.add_edge(
bond.GetBeginAtomIdx(),
bond.GetEndAtomIdx(),
bond_type=bond.GetBondType()
)
return G
graphs = []
with Chem.SDMolSupplier('file.sdf') as suppl:
for mol in suppl:
if mol is None:
continue
graphs.append(mol_to_nx(mol))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment