File _collapse_ring.py
has 862 lines of code (exceeds 250 allowed). Consider refactoring. Open
########################################################################################################################
__doc__ = \
"""
This is the ring collapsing code.
Function collapse_ring
has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring. Open
def collapse_ring(self, mol: Chem.Mol) -> Chem.Mol:
"""
Collapses a ring(s) into a single dummy atom(s).
Stores data as JSON in the atom.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
_MonsterRing
has 37 functions (exceeds 20 allowed). Consider refactoring. Open
class _MonsterRing(_MonsterJoinNeigh):
def collapse_mols(self, mols: List[Chem.Mol]):
mols = [self.collapse_ring(mol) for mol in mols]
[self.offset(mol) for mol in mols]
Function _join_internally
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def _join_internally(self, mol: Chem.Mol, severe: bool = False) -> Chem.Mol:
"""
The last check to see if the mol is connected.
This differs (and calls) ``join_neighboring_mols``
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _renumber_original_indices
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def _renumber_original_indices(self, mol: Chem.Mol,
mapping: Dict[int, int],
name_restriction: Optional[str] = None):
"""
Renumbers the indices in the ring virtual atom to new mapping.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _detriangulate
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _detriangulate(self, mol: Chem.RWMol) -> None:
"""
Prevents novel cyclopropanes and cyclobutanes.
:param mol:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _determine_mergers_novel_other_pair
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _determine_mergers_novel_other_pair(self,
mol: Chem.RWMol,
ringcore: Chem.Atom,
other: Chem.Atom) -> List[Tuple[int, int]]:
"""
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function merge_pairing_lists
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def merge_pairing_lists(self,
nonunique_pairs: List[Tuple[Chem.Atom, Chem.Atom]],
ringcore_first=True) \
-> List[Tuple[Chem.Atom, Chem.Atom]]:
# complicated because mol.GetAtomWithIdx(2) == mol.GetAtomWithIdx(2) is False
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _get_novel_other_bonded_pairs
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _get_novel_other_bonded_pairs(self, rings) -> List[Tuple[Chem.Atom, Chem.Atom]]:
pairs = []
for ring in rings:
# ring: Dict[str, List[Any]]
ringcore = ring['atom'] # Chem.Atom
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if neigh not in morituri:
mol.AddBond(center_i, neigh, bt)
new_bond = mol.GetBondBetweenAtoms(center_i, neigh)
BondProvenance.set_bond(new_bond, 'original')
else:
Consider simplifying this complex logical expression. Open
if ringcore_first and atom_a.HasProp('_current_is') and not atom_b.HasProp('_current_is'):
ringcore = ai
other = bi
pairing = f'{ringcore}-{other}'
elif ringcore_first and atom_b.HasProp('_current_is') and not atom_a.HasProp('_current_is'):
Function _restore_bond
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _restore_bond(self, mol: Chem.RWMol,
Function _get_merging_penalties
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _get_merging_penalties(self, mol, shape: Tuple[int, int], indices_ring):
"""
confusingly this is a different set of penalties to `_get_joining_penalties` which is for joining
:param mol:
:param shape:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _place_ring_atoms
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _place_ring_atoms(self, mol, rings: List[Dict[str, Union[Chem.Atom, List[Any]]]]):
"""
Plase all atoms stored in rings.
:param mol:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function expand_ring
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def expand_ring(self, mol: Chem.Mol) -> Chem.Mol:
"""
Undoes collapse ring
:param mol: untouched.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _get_new_index
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _get_new_index(self, mol: Chem.Mol, old: int, search_collapsed=True,
name_restriction: Optional[str] = None) -> int:
"""
Given an old index check in ``_ori_i`` for what the current one is.
NB. ring placeholder will be -1 and these also have ``_ori_is``. a JSON of the ori_i they summarise.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _determine_mergers_novel_ringcore_pair
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _determine_mergers_novel_ringcore_pair(self,
mol: Chem.RWMol,
ringcore_A: Chem.Atom,
ringcore_B: Chem.Atom) -> List[Tuple[int, int]]:
"""
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function offset
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def offset(self, mol: Chem.Mol):
"""
This is to prevent clashes.
The numbers of the ori indices stored in collapsed rings are offset by the class variable (_collapsed_ring_offset)
multiples of 100. (autoincrements to avoid dramas)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _restore_original_bonding
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _restore_original_bonding(self, mol: Chem.RWMol, rings: List[Dict[str, List[Any]]]) -> None:
"""
Restore the bonding stored in the ringcore.
The data of each collapsed atom is given by ``self._get_expansion_for_atom(ring, i)``
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _get_novel_ringcore_bonded_pairs
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _get_novel_ringcore_bonded_pairs(self, rings):
"""
called by _get_novel_ringcore_pairs alongside _get_close_novel_ringcores
Opposite of _get_novel_other_bonded_pairs
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _get_expansion_for_atom
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _get_expansion_for_atom(self, ring: Dict[str, List[Any]], i: int) -> Dict[str, Any]:
"""
``_get_expansion_data`` returns from a mol the "expansion data for the rings"
``_get_expansion_for_atom`` given one of the list of the data from the latter (representing a ring core)
and an index of which of the internal atoms that were collapsed return a dictionary of details
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"