| from rdkit import Chem
|
| import networkx as nx
|
|
|
| # define the smiles string and covert it into a molecule sturcture ------------
|
| caffeine_smiles = 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C'
|
| caffeine_mol = Chem.MolFromSmiles(caffeine_smiles)
|
| G = nx.Graph()
|
|
|
| i=0
|
| for atom in caffeine_mol.GetAtoms():
|
| G.add_node(atom.GetIdx(),
|
| w_label=atom.GetSymbol()
|
| )
|
| G.nodes[i]['label'] = atom.GetSymbol()
|
| i+=1
|
|
|
| for bond in caffeine_mol.GetBonds():
|
| G.add_edge(bond.GetBeginAtomIdx(),
|
| bond.GetEndAtomIdx(),
|
| weight=0)
|
|
|
| nx.write_gml(G, "caffeine.gml")
|