Skip to content

Commit

Permalink
drop polymer mass function
Browse files Browse the repository at this point in the history
  • Loading branch information
Eloy Felix committed Apr 26, 2024
1 parent edc266c commit 1fe127b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 49 deletions.
52 changes: 4 additions & 48 deletions libRDChEBI/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,13 @@ def get_net_charge(molfile):


def _create_or_add_one(dictionary, key):
if dictionary.get(key):
dictionary[key] += 1
else:
dictionary[key] = 1
dictionary[key] = dictionary.get(key, 0) + 1
return dictionary


def _create_or_add_one_nested(dictionary, key1, key2):
if dictionary.get(key1):
if dictionary[key1].get(key2):
dictionary[key1][key2] += 1
else:
dictionary[key1][key2] = 1
else:
dictionary[key1] = {key2: 1}
dictionary[key1] = dictionary.get(key1, {})
dictionary[key1][key2] = dictionary[key1].get(key2, 0) + 1
return dictionary


Expand Down Expand Up @@ -259,42 +251,6 @@ def get_conn_atoms(mol, atom_idx):
return connected_atoms


def get_polymer_mass(molfile, avg=True):
if avg:
func = Descriptors.MolWt
else:
func = Descriptors.ExactMolWt
mol = parse_molblock(molfile)
mol = update_mol_valences(mol)
rwmol = Chem.RWMol(mol)
masses = []
atoms_in_sgroups = []
for sg in Chem.GetMolSubstanceGroups(rwmol):
sub_mol = Chem.RWMol()
for atm in sg.GetAtoms():
atom = rwmol.GetAtomWithIdx(atm)
sub_mol.AddAtom(atom)
atoms_in_sgroups.append(atm)

mass = round(func(sub_mol), 5)
if sg.HasProp("LABEL"):
label = sg.GetProp("LABEL")
else:
label = ""
mass = f"({mass}){label}"
masses.append(mass)

# calc the mass for the rest of atoms
rwmol.BeginBatchEdit()
for atm in atoms_in_sgroups:
rwmol.RemoveAtom(atm)
rwmol.CommitBatchEdit()
rest_mass = round(func(rwmol), 5)
if rest_mass > 0.0: # potential remaining '*' have mass 0.0
masses.append(str(rest_mass))
return "+".join(masses)


def get_mass_from_formula(formula, average=True):
"""
average=True: avg mass
Expand All @@ -316,4 +272,4 @@ def get_mass_from_formula(formula, average=True):
else:
elem_mass = periodic_table.GetMostCommonIsotopeMass(matches[idx])
mass += elem_mass * mult
return round(mass, 5)
return mass
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if __name__ == "__main__":
setup(
name="libRDChEBI",
version="0.2.4",
version="0.2.5",
author="Eloy Félix",
author_email="[email protected]",
description="RDKit library to deal with ChEBI's chemistry",
Expand Down

0 comments on commit 1fe127b

Please sign in to comment.