<jupyter_start><jupyter_text>How to calculate total charge of a molecule?<jupyter_code>from openeye import oechem, oedepict
import oenotebook as oenb
import pandas as pd

def depict_smiles(smiles):
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol,smiles)
    return oenb.draw_mol(mol)
def get_total_charge(smiles):
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol,smiles)
    
    total_charge = 0
    for a in mol.GetAtomIter():
        total_charge += a.GetFormalCharge()
    return total_charge

def compare_total_charge(smiles1, smiles2):
    total_charge1 = get_total_charge(smiles1)
    total_charge2 = get_total_charge(smiles2)
    if total_charge1 == total_charge2:
        return True
    else:
        return False
smiles = "[H]NC1=[NH+]C=[NH+]C2=C1C=NN2c3ccccc3"
depict_smiles(smiles)
get_total_charge(smiles)
smiles1 = "[H]NC1=[NH+]C=[NH+]C2=C1C=NN2c3ccccc3"
smiles2 = "NC1=[NH+]C=[NH+]C2=C1C=NN2c3ccccc3"
compare_total_charge(smiles1, smiles2)
smiles1 = 'c1cc2c(cc1O)c3c(o2)C(=[OH+])NCCC3'
smiles2 = 'c1cc2c(cc1[O-])c3c(o2)C(=NCCC3)[O-]'
compare_total_charge(smiles1, smiles2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1266607617360496, 'fraction_numerical': 0.04162976085031001, 'mean_word_length': 5.531791907514451, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '377235', 'license': 'MIT', 'n_tokens_mistral': 519, 'n_tokens_neox': 498, 'n_words': 73, 'path': 'pKa_microstate_enumeration/corrected_microstates_v1_3_2/calc_total_charge.ipynb', 'repo_name': 'choderalab/sampl6-logD-compound-selection', 'size': '1129'}