protons/app/modeller.py
Function addHydrogens
has a Cognitive Complexity of 186 (exceeds 5 allowed). Consider refactoring. Open
Open
def addHydrogens(self, forcefield=None, pH=None, variants=None, platform=None):
"""Add missing hydrogens to the model.
This function automatically changes compatible residues into their constant-pH variant if no variant is specified.:
- 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
File modeller.py
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
# coding=utf-8
"""Pre-configured OpenMM Modeller object for use with the default protons forcefield. Modified from original source code by Peter Eastman."""
from .topology import Topology
from simtk.openmm.app import modeller
Consider simplifying this complex logical expression. Open
Open
if residue.name in Modeller._residueHydrogens:
# Add hydrogens. First select which variant to use.
spec = Modeller._residueHydrogens[residue.name]
variant = variants[residue.index]
Avoid deeply nested control flow statements. Open
Open
if residue.name == "ASP":
variant = "AS4"
if variant is not None and variant not in spec.variants:
Avoid deeply nested control flow statements. Open
Open
if residue.name == "GLU":
variant = "GL4"
if residue.name == "ASP":
Avoid deeply nested control flow statements. Open
Open
if (
removeExtraHydrogens
and parent.element == elem.hydrogen
and not any(parent.name == h.name for h in hydrogens)
):
Avoid deeply nested control flow statements. Open
Open
if residue.name == "CYS":
# If this is part of a disulfide, use CYX.
sulfur = [
atom
Avoid deeply nested control flow statements. Open
Open
if residue.name == "HIS":
variant = "HIP"
if residue.name == "GLU":
Avoid deeply nested control flow statements. Open
Open
if (
atom.element == elem.oxygen
and len(bondedTo[index]) == 2
and elem.hydrogen in (a.element for a in bondedTo[index])
):
Avoid deeply nested control flow statements. Open
Open
if parent in parents:
# Match expected hydrogens with existing ones and find which ones need to be added.
existing = [
atom