Created
January 10, 2026 00:15
-
-
Save daenuprobst/9df8fe18a6bb06cca2a3adbed9f7c777 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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