Home > Mateda2.0 > functions > protein > EvalChainFunctional.m

# EvalChainFunctional

## PURPOSE

Given a chain of molecules, calculates the numer of Collisions with

## SYNOPSIS

function[Collisions,Overlappings,Pos] = EvalChainFunctional(vector)

## DESCRIPTION

     Given a chain of molecules, calculates the numer of Collisions with
     neighboring same sign molecules, and the number of Overlappings molecules.
     HPInitConf is the configuration of the Chain of molecules
     vector is the set of moves for all

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- EvaluateEnergyFunctional [energy] = EvaluateEnergyFunctional(vector)

## SOURCE CODE

    0001 function[Collisions,Overlappings,Pos] =  EvalChainFunctional(vector)
    0002 % Given a chain of molecules, calculates the numer of Collisions with
    0003 % neighboring same sign molecules, and the number of Overlappings molecules.
    0004 % HPInitConf is the configuration of the Chain of molecules
    0005 % vector is the set of moves for all
    0006
    0007 global HPInitConf;
    0008 sizeChain = size(vector,2);
    0009
    0010 Collisions = 0;
    0011 Overlappings = 0;
    0012
    0013
    0014 Pos = zeros(sizeChain,2);
    0015
    0016 Pos(1,1) = 0;  %Position for the initial molecule
    0017 Pos(1,2) = 0;
    0018
    0019 Pos(2,1) = 1;  %Position for the second molecule
    0020 Pos(2,2) = 0;
    0021
    0022  for i=3:sizeChain
    0023
    0024  if(Pos(i-1,2)==Pos(i-2,2))
    0025   if (vector(i)==0)            %UP MOVE
    0026    Pos(i,1) = Pos(i-1,1);
    0027    Pos(i,2) = Pos(i-1,2) + (Pos(i-1,1)-Pos(i-2,1));
    0028   elseif (vector(i)==1)        %FORWARD MOVE
    0029    Pos(i,1) = Pos(i-1,1) + (Pos(i-1,1)-Pos(i-2,1));
    0030    Pos(i,2) = Pos(i-1,2);
    0031   else                         %DOWN MOVE
    0032    Pos(i,1) = Pos(i-1,1);
    0033    Pos(i,2) = Pos(i-1,2) - (Pos(i-1,1)-Pos(i-2,1));
    0034   end
    0035   end
    0036 if (Pos(i-1,1)==Pos(i-2,1))
    0037   if (vector(i)==0)            %UP MOVE
    0038     Pos(i,2) = Pos(i-1,2);
    0039     Pos(i,1) = Pos(i-1,1) -  (Pos(i-1,2)-Pos(i-2,2));
    0040   elseif (vector(i)==1)        %FORWARD MOVE
    0041     Pos(i,2) = Pos(i-1,2) +  (Pos(i-1,2)-Pos(i-2,2));
    0042     Pos(i,1) = Pos(i-1,1);
    0043   else                         %DOWN MOVE
    0044     Pos(i,2) = Pos(i-1,2);
    0045     Pos(i,1) = Pos(i-1,1) + (Pos(i-1,2)-Pos(i-2,2));
    0046   end
    0047  end
    0048
    0049    for j=1:i-2,   % Check for Overlappings and Collissions in all the    molecules except the previous one
    0050     if(Pos(i,1)==Pos(j,1) & Pos(i,2)==Pos(j,2))
    0051       Overlappings = Overlappings + 1;
    0052     elseif (HPInitConf(i)==0  & HPInitConf(j)==0)
    0053      if (Pos(i,1)==Pos(j,1) & Pos(i,2)==Pos(j,2)-1)
    0054         Collisions =   Collisions + 2;
    0055      end
    0056      if (Pos(i,1)==Pos(j,1)+1 & Pos(i,2)==Pos(j,2))
    0057         Collisions =   Collisions + 2;
    0058      end
    0059      if (Pos(i,1)==Pos(j,1) & Pos(i,2)==Pos(j,2)+1)
    0060         Collisions =   Collisions + 2;
    0061      end
    0062      if (Pos(i,1)==Pos(j,1)-1 & Pos(i,2)==Pos(j,2))
    0063         Collisions =   Collisions + 2;
    0064      end
    0065     elseif (HPInitConf(i)+HPInitConf(j)>0)
    0066      if (Pos(i,1)==Pos(j,1) & Pos(i,2)==Pos(j,2)-1)
    0067         Collisions =   Collisions - 1;
    0068      end
    0069      if (Pos(i,1)==Pos(j,1)+1 & Pos(i,2)==Pos(j,2))
    0070         Collisions =   Collisions - 1;
    0071      end
    0072      if (Pos(i,1)==Pos(j,1) & Pos(i,2)==Pos(j,2)+1)
    0073         Collisions =   Collisions - 1;
    0074      end
    0075      if (Pos(i,1)==Pos(j,1)-1 & Pos(i,2)==Pos(j,2))
    0076         Collisions =   Collisions - 1;
    0077      end
    0078     end
    0079  end
    0080 end
    0081
    0082 %HPInitConf =  [zeros(1,12),1,0,1,0,1,1,0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,0,1,1,0,1,0,1,zeros(1,12)];
    0083
    0084
    0085
    0086
    0087
    0088