import networkx as nx


def mol_to_nx(mol):
	"""Converts RDKit mol to NetworkX graph object.

	Parameters
	----------
	mol : RDKit mol
		RDKit molecule.

	Returns
	-------
	G : Networkx Graph.
		Graph object.

	References
	----------
	`keras-molecules <https://github.com/dakoner/keras-molecules/blob/dbbb790e74e406faa70b13e8be8104d9e938eba2/convert_rdkit_to_networkx.py#L17>`__
	"""
	G = nx.Graph()

	for atom in mol.GetAtoms():
		G.add_node(atom.GetIdx(),
				   atomic_num=atom.GetAtomicNum(),
				   formal_charge=atom.GetFormalCharge(),
				   chiral_tag=atom.GetChiralTag(),
				   hybridization=atom.GetHybridization(),
				   num_explicit_hs=atom.GetNumExplicitHs(),
				   is_aromatic=atom.GetIsAromatic())
	for bond in mol.GetBonds():
		G.add_edge(bond.GetBeginAtomIdx(),
				   bond.GetEndAtomIdx(),
				   bond_type=bond.GetBondType())
	return G