choderalab/protons

View on GitHub
protons/app/modeller.py

Summary

Maintainability
F
5 days
Test Coverage

Function addHydrogens has a Cognitive Complexity of 186 (exceeds 5 allowed). Consider refactoring.
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.:

Severity: Minor
Found in protons/app/modeller.py - About 3 days to fix

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

# 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
Severity: Minor
Found in protons/app/modeller.py - About 3 hrs to fix

    Consider simplifying this complex logical expression.
    Open

                    if residue.name in Modeller._residueHydrogens:
                        # Add hydrogens.  First select which variant to use.
    
                        spec = Modeller._residueHydrogens[residue.name]
                        variant = variants[residue.index]
    Severity: Critical
    Found in protons/app/modeller.py - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                              if residue.name == "ASP":
                                  variant = "AS4"
                          if variant is not None and variant not in spec.variants:
      Severity: Major
      Found in protons/app/modeller.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if residue.name == "GLU":
                                    variant = "GL4"
                                if residue.name == "ASP":
        Severity: Major
        Found in protons/app/modeller.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if (
                                      removeExtraHydrogens
                                      and parent.element == elem.hydrogen
                                      and not any(parent.name == h.name for h in hydrogens)
                                  ):
          Severity: Major
          Found in protons/app/modeller.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if residue.name == "CYS":
                                        # If this is part of a disulfide, use CYX.
            
                                        sulfur = [
                                            atom
            Severity: Major
            Found in protons/app/modeller.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if residue.name == "HIS":
                                          variant = "HIP"
                                      if residue.name == "GLU":
              Severity: Major
              Found in protons/app/modeller.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if (
                                            atom.element == elem.oxygen
                                            and len(bondedTo[index]) == 2
                                            and elem.hydrogen in (a.element for a in bondedTo[index])
                                        ):
                Severity: Major
                Found in protons/app/modeller.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if parent in parents:
                                              # Match expected hydrogens with existing ones and find which ones need to be added.
                  
                                              existing = [
                                                  atom
                  Severity: Major
                  Found in protons/app/modeller.py - About 45 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status