Skip to content

Commit

Permalink
Remove duplicated method getNumberOfRadicalElectrons
Browse files Browse the repository at this point in the history
Was identical to getRadicalCount
  • Loading branch information
mliu49 committed Feb 23, 2017
1 parent 7cadcbd commit 60bbcfd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rmgpy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def failsSpeciesConstraints(species):

maxRadicals = speciesConstraints.get('maximumRadicalElectrons', -1)
if maxRadicals != -1:
if (struct.getNumberOfRadicalElectrons() > maxRadicals):
if (struct.getRadicalCount() > maxRadicals):
return True

maxIsotopes = speciesConstraints.get('maximumIsotopicAtoms', -1)
Expand Down
2 changes: 0 additions & 2 deletions rmgpy/molecule/molecule.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ cdef class Molecule(Graph):

cpdef int getNumAtoms(self, str element=?)

cpdef int getNumberOfRadicalElectrons(self)

cpdef Graph copy(self, bint deep=?)

cpdef deleteHydrogens(self)
Expand Down
16 changes: 3 additions & 13 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,9 @@ def getMolecularWeight(self):

def getRadicalCount(self):
"""
Return the number of unpaired electrons.
Return the total number of radical electrons on all atoms in the
molecule. In this function, monoradical atoms count as one, biradicals
count as two, etc.
"""
cython.declare(atom=Atom, radicals=cython.short)
radicals = 0
Expand All @@ -872,18 +874,6 @@ def getNumAtoms(self, element = None):
numAtoms += 1
return numAtoms

def getNumberOfRadicalElectrons(self):
"""
Return the total number of radical electrons on all atoms in the
molecule. In this function, monoradical atoms count as one, biradicals
count as two, etc.
"""
cython.declare(numRadicals=cython.int, atom=Atom)
numRadicals = 0
for atom in self.vertices:
numRadicals += atom.radicalElectrons
return numRadicals

def copy(self, deep=False):
"""
Create a copy of the current graph. If `deep` is ``True``, a deep copy
Expand Down
8 changes: 4 additions & 4 deletions rmgpy/molecule/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def fixCharge(mol, u_indices):
return

is_charged = sum([abs(at.charge) for at in mol.atoms]) != 0
is_correct = mol.getNumberOfRadicalElectrons() == (mol.multiplicity - 1)
is_correct = mol.getRadicalCount() == (mol.multiplicity - 1)
if mol.multiplicity < 3 or is_correct or not is_charged:
return

Expand Down Expand Up @@ -667,7 +667,7 @@ def fix_triplet_to_singlet(mol, p_indices):

for at in mol.atoms:
index = mol.atoms.index(at) + 1
if mol.getNumberOfRadicalElectrons() == 2 and index in p_indices:
if mol.getRadicalCount() == 2 and index in p_indices:
at.lonePairs += 1
at.radicalElectrons -= 2
p_indices.remove(index)
Expand Down Expand Up @@ -846,7 +846,7 @@ def fix_unsaturated_bond(mol, indices, aug_inchi):
of atoms that should be unpaired electrons left.
"""

correct = mol.getNumberOfRadicalElectrons() == (mol.multiplicity - 1)
correct = mol.getRadicalCount() == (mol.multiplicity - 1)

if not correct and not indices:
raise Exception( 'Cannot correct {} based on {} by converting unsaturated bonds into unpaired electrons...'\
Expand All @@ -856,5 +856,5 @@ def fix_unsaturated_bond(mol, indices, aug_inchi):

while not correct and unsaturated and len(indices) > 1:
mol = fix_unsaturated_bond_to_biradical(mol, aug_inchi.inchi, indices)
correct = mol.getNumberOfRadicalElectrons() == (mol.multiplicity - 1)
correct = mol.getRadicalCount() == (mol.multiplicity - 1)
unsaturated = isUnsaturated(mol)

0 comments on commit 60bbcfd

Please sign in to comment.