A small molecule controls an interaction of which the protein is a participant.
@return pattern
344209
public static Pattern chemicalAffectsProteinThroughControl()
	{
		Pattern p = new Pattern(SmallMoleculeReference.class, "controller SMR");
		p.add(erToPE(), "controller SMR", "controller simple PE");
		p.add(notGeneric(), "controller simple PE");
		p.add(linkToComplex(), "controller simple PE", "controller PE");
		p.add(peToControl(), "controller PE", "Control");
		p.add(controlToInter(), "Control", "Interaction");
		p.add(new NOT(participantER()), "Interaction", "controller SMR");
		p.add(participant(), "Interaction", "affected PE");
		p.add(linkToSpecific(), "affected PE", "affected simple PE");
		p.add(new Type(SequenceEntity.class), "affected simple PE");
		p.add(peToER(), "affected simple PE", "affected generic ER");
		p.add(linkedER(false), "affected generic ER", "affected ER");
		return p;
	}
377495
protected function lock()
    {
        if ( $this->subject == 'user' ) {
           return $this->manager->caller( $this->user );
        } elseif ( $this->subject == 'role' ) {
           return $this->manager->role( $this->role );
        } else {
            throw new \Exception("Caller not allowed: $this->subject");
        }
    }
501093
private function interfaceDeclaration() {
    $node = new InterfaceNode();
    $this->matchDocComment($node);
    $this->mustMatch(T_INTERFACE, $node);
    $name_node = new NameNode();
    $this->mustMatch(T_STRING, $name_node, NULL, TRUE);
    $node->addChild($name_node, 'name');
    if ($this->tryMatch(T_EXTENDS, $node)) {
      $extends = new CommaListNode();
      do {
        $extends->addChild($this->name());
      } while ($this->tryMatch(',', $extends));
      $node->addChild($extends, 'extends');
    }
    $this->matchHidden($node);
    $statement_block = new StatementBlockNode();
    $this->mustMatch('{', $statement_block, NULL, FALSE, TRUE);
    while ($this->currentType !== NULL && $this->currentType !== '}') {
      $this->matchHidden($statement_block);
      if ($this->currentType === T_CONST) {
        $statement_block->addChild($this->_const());
      }
      else {
        $statement_block->addChild($this->interfaceMethod());
      }
    }
    $this->mustMatch('}', $statement_block, NULL, TRUE, TRUE);
    $node->addChild($statement_block, 'statements');
    return $node;
  }
297221
public static Pattern controlsDegradationIndirectly()
	{
		Pattern p = controlsStateChange();
		p.add(new Size(new ParticipatesInConv(RelType.INPUT), 1, Size.Type.EQUAL), "output PE");
		p.add(new Empty(peToControl()), "output PE");
		p.add(new ParticipatesInConv(RelType.INPUT), "output PE", "degrading Conv");
		p.add(new NOT(type(ComplexAssembly.class)), "degrading Conv");
		p.add(new Size(participant(), 1, Size.Type.EQUAL), "degrading Conv");
		p.add(new Empty(new Participant(RelType.OUTPUT)), "degrading Conv");
		p.add(new Empty(convToControl()), "degrading Conv");
		p.add(equal(false), "degrading Conv", "Conversion");
		return p;
	}
129640
public @NonNull SelectorComponent pattern(final @NonNull String pattern) {
    return new SelectorComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, requireNonNull(pattern, "pattern"));
  }
447516
public function pattern($pattern = null)
        {
            if ($pattern === null) return $this->rulePattern;

            $this->rulePattern = $pattern;

            return $this;
        }
392289
private int getGroupTypIndicator(PolymerType polymerType) {
		if(PolymerType.PROTEIN_ONLY.contains(polymerType)){
			return 1;
		}
		if(PolymerType.POLYNUCLEOTIDE_ONLY.contains(polymerType)){
			return 2;
		}
		return 0;
	}
811173
public function getMolecularFormula()
    {
        $acids = str_split($this->getSequence(), 1);

        $frequency = array(
            'C' => 0,
            'H' => 0,
            'N' => 0,
            'O' => 0,
            'S' => 0
        );

        foreach ($acids as $acid) {
            $composition = AminoAcidComposition::getFormula($acid);

            $matches = array();
            preg_match_all('/([A-Z][a-z]?)([0-9]*)/', $composition, $matches, PREG_SET_ORDER);

            foreach ($matches as $match) {
                $chemical = $match[1];
                $count = $match[2];

                if (! isset($frequency[$chemical])) {
                    $frequency[$chemical] = 0;
                }

                $frequency[$chemical] += $count == '' ? 1 : $count;
            }
        }

        // Remove hydrogen and oxygen from C-TERM
        $frequency['H'] -= count($acids) - 1;
        $frequency['O'] -= count($acids) - 1;

        // Remove hydrogen from N-TERM.
        $frequency['H'] -= count($acids) - 1;

        $formula = '';
        foreach ($frequency as $chemical => $count) {
            if ($count == 0) {
                continue;
            }

            $formula .= $chemical;

            if ($count > 1) {
                $formula .= $count;
            }
        }

        return $formula;
    }
449402
public function getMonoisotopicMass()
    {
        $acids = str_split($this->getSequence(), 1);

        $mass = ChemicalConstants::HYDROGEN_MASS + ChemicalConstants::HYDROGEN_MASS + ChemicalConstants::OXYGEN_MASS;

        foreach ($acids as $acid) {
            switch ($acid) {
                case 'X':
                case 'B':
                case 'Z':
                    continue;
                default:
                    $mass += AminoAcidMono::getMonoisotopicMass($acid);
                    break;
            }
        }

        // Add modification mass
        // Catch modification on position, residue or terminus
        foreach ($this->getModifications() as $modification) {
            if (! is_null($modification->getLocation())) {
                $mass += $modification->getMonoisotopicMass();
                continue;
            }

            switch ($modification->getPosition()) {
                case Modification::POSITION_NTERM:
                case Modification::POSITION_PROTEIN_NTERM:
                    // TODO: Handle protein level safely
                    // A peptide can be both at protein n-term and not since multiple proteins supported
                    $nTerm = $this->sequence[0];
                    if (in_array($nTerm, $modification->getResidues())) {
                        $mass += $modification->getMonoisotopicMass();
                    }

                    break;

                case Modification::POSITION_CTERM:
                case Modification::POSITION_PROTEIN_CTERM:
                    // TODO: Handle protein level safely
                    // A peptide can be both at protein n-term and not since multiple proteins supported
                    $cTerm = $this->sequence[strlen($this->sequence) - 1];
                    if (in_array($cTerm, $modification->getResidues())) {
                        $mass += $modification->getMonoisotopicMass();
                    }

                    break;

                default:
                    foreach ($acids as $acid) {
                        if (in_array($acid, $modification->getResidues())) {
                            $mass += $modification->getMonoisotopicMass();
                        }
                    }
                    break;
            }
        }

        return $mass;
    }
693062
public static Pattern catalysisPrecedes(Blacklist blacklist)
	{
		Pattern p = new Pattern(SequenceEntityReference.class, "first ER");
		p.add(linkedER(true), "first ER", "first generic ER");
		p.add(erToPE(), "first generic ER", "first simple controller PE");
		p.add(linkToComplex(), "first simple controller PE", "first controller PE");
		p.add(peToControl(), "first controller PE", "first Control");
		p.add(controlToConv(), "first Control", "first Conversion");
		p.add(new Participant(RelType.OUTPUT, blacklist, true), "first Control", "first Conversion", "linker PE");
		p.add(new NOT(new ConstraintChain(new ConversionSide(ConversionSide.Type.OTHER_SIDE), linkToSpecific())), "linker PE", "first Conversion", "linker PE");
		p.add(type(SmallMolecule.class), "linker PE");
		p.add(new ParticipatesInConv(RelType.INPUT, blacklist), "linker PE", "second Conversion");
		p.add(new NOT(new ConstraintChain(new ConversionSide(ConversionSide.Type.OTHER_SIDE), linkToSpecific())), "linker PE", "second Conversion", "linker PE");
		p.add(equal(false), "first Conversion", "second Conversion");

		// make sure that conversions are not replicates or reverse of each other
		// and also outward facing sides of reactions contain at least one non ubique
		p.add(new ConstraintAdapter(3, blacklist)
		{
			@Override
			public boolean satisfies(Match match, int... ind)
			{
				Conversion cnv1 = (Conversion) match.get(ind[0]);
				Conversion cnv2 = (Conversion) match.get(ind[1]);
				SmallMolecule linker = (SmallMolecule) match.get(ind[2]);

				Set<PhysicalEntity> input1 = cnv1.getLeft().contains(linker) ? cnv1.getRight() : cnv1.getLeft();
				Set<PhysicalEntity> input2 = cnv2.getLeft().contains(linker) ? cnv2.getLeft() : cnv2.getRight();
				Set<PhysicalEntity> output1 = cnv1.getLeft().contains(linker) ? cnv1.getLeft() : cnv1.getRight();
				Set<PhysicalEntity> output2 = cnv2.getLeft().contains(linker) ? cnv2.getRight() : cnv2.getLeft();

				if (input1.equals(input2) && output1.equals(output2)) return false;
				if (input1.equals(output2) && output1.equals(input2)) return false;

				if (blacklist != null)
				{
					Set<PhysicalEntity> set = new HashSet<PhysicalEntity>(input1);
					set = blacklist.getNonUbiques(set, RelType.INPUT);
					set.removeAll(output2);
					if (set.isEmpty())
					{
						set.addAll(output2);
						set = blacklist.getNonUbiques(set, RelType.OUTPUT);
						set.removeAll(input1);

						if (set.isEmpty()) return false;
					}
				}
				return true;
			}
		}, "first Conversion", "second Conversion", "linker PE");

		p.add(new RelatedControl(RelType.INPUT, blacklist), "linker PE", "second Conversion", "second Control");
		p.add(controllerPE(), "second Control", "second controller PE");
		p.add(new NOT(compToER()), "second controller PE", "first ER");
		p.add(linkToSpecific(), "second controller PE", "second simple controller PE");
		p.add(type(SequenceEntity.class), "second simple controller PE");
		p.add(peToER(), "second simple controller PE", "second generic ER");
		p.add(linkedER(false), "second generic ER", "second ER");
		p.add(equal(false), "first ER", "second ER");
		return p;
	}
436652
public static Pattern bindsTo()
	{
		Pattern p = new Pattern(ProteinReference.class, "first PR");
		p.add(erToPE(), "first PR", "first simple PE");
		p.add(linkToComplex(), "first simple PE", "Complex");
		p.add(new Type(Complex.class), "Complex");
		p.add(linkToSpecific(), "Complex", "second simple PE");
		p.add(peToER(), "second simple PE", "second PR");
		p.add(equal(false), "first PR", "second PR");
		return p;
	}
173578
public function bind()
    {
        if (func_num_args()) {
            $bindings = new Bindings(func_get_args(), $this->rules);
            $this->rules = $bindings->rules();
        }

        return $this;
    }
18271
public static Pattern inSameActiveComplex()
	{
		Pattern p = inSameComplex();
		p.add(new ActivityConstraint(true), "Complex");
		return p;
	}
47678
public static Pattern inComplexWith()
	{
		Pattern p = new Pattern(SequenceEntityReference.class, "Protein 1");
		p.add(linkedER(true), "Protein 1", "generic Protein 1");
		p.add(erToPE(), "generic Protein 1", "SPE1");
		p.add(linkToComplex(), "SPE1", "PE1");
		p.add(new PathConstraint("PhysicalEntity/componentOf"), "PE1", "Complex");
		p.add(new PathConstraint("Complex/component"), "Complex", "PE2");
		p.add(equal(false), "PE1", "PE2");
		p.add(linkToSpecific(), "PE2", "SPE2");
		p.add(peToER(), "SPE2", "generic Protein 2");
		p.add(linkedER(false), "generic Protein 2", "Protein 2");
		p.add(equal(false), "Protein 1", "Protein 2");
		p.add(new Type(SequenceEntityReference.class), "Protein 2");
		return p;
	}
1199180
protected function wrapInControlGroup()
    {
        // Add generic stuff
        $this->addGroupClass('list-form-group');

        // Use the controller description for blockhelp
        if (!$this->hasHelp()) {
            $this->blockhelp($this->controller->description());
        }

        // Show no results if there is no parent specified
        if (empty($this->parent_item)) {
            $this->addGroupClass('note');

            return $this->group->wrapField(Former::note($this->label_text, trans('decoy::form.listing.pending_save', ['model' => $this->label_text, 'description' => $this->controller->description()])));
        }

        // Add create button if we have permission and if there is a parent item
        if (app('decoy.user')->can('create', $this->controller)) {
            $this->group->setLabel(
                '<a href="'.$this->getIndexURL().'">'
                .$this->label_text
                .'</a>'
                .$this->makeCreateBtn()
            );
        }

        // Return the wrapped field
        return $this->group->wrapField($this);
    }
327885
public function getCompositionRules()
    {
        $subExpressions = array();
        foreach ($this->components as $irp) {
        	$subExpressions[] = new CommonExpression('variable', array('identifier' => $irp->getOutcome()->getIdentifier()));
        }
        $sum = new CommonExpression('sum', array());
        $sum->setSubExpressions($subExpressions);
        $summationRule = new SetOutcomeVariable($this->outcomeIdentifier, $sum);
        
        $returnValue = array($summationRule);

        return (array) $returnValue;
    }
388509
public Pattern52 clonePattern() {
        Pattern52 cloned = new Pattern52();
        cloned.setBoundName( getBoundName() );
        cloned.setChildColumns( new ArrayList<ConditionCol52>( getChildColumns() ) );
        cloned.setEntryPointName( getEntryPointName() );
        cloned.setFactType( getFactType() );
        cloned.setNegated( isNegated() );
        cloned.setWindow( getWindow() );
        return cloned;
    }