UnityMol  0.9.6-875
UnityMol viewer / In developement
BFactorRep.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 using Molecule.Model;
5 using UI;
6 using Molecule.Control;
7 
8 public class BFactorRep {
9  public static List<float[]> backupCaList = MoleculeModel.backupCatomsLocationlist ;
11  public static List<float> backupBfactCAList;
12  public static float minValue;
13  public static float maxValue;
14  public static string minval = "";
15  public static string maxval = "";
16 
17  public static void CreateBFRep() {
18  List<float[]> alist = MoleculeModel.atomsLocationlist;
19  List<float[]> calist = new List<float[]>(MoleculeModel.backupCatomsLocationlist);
20  List<string> caChainlist = new List<string>(MoleculeModel.backupCaSplineChainList);
21  List<string> atomsNameList = MoleculeModel.atomsNamelist;
22  List<AtomModel> typelist = MoleculeModel.atomsTypelist;
23  //C.R
24  List<float> Bfactorlist = MoleculeModel.BFactorList;
25  List<int> residlist = MoleculeModel.residueIds;
26  List<float> BfactCAlist = new List<float> ();
27  //List<string> resnamelist = MoleculeModel.atomsResnamelist;
28 
29 
30  // Trace interpolation from C-alpha positions
31  // Only if there are more than 2 C-alpha
32 
33  if(calist.Count > 2) {
34 
35  // Compute bfactor mean by residue
36  int comp = 0; //counter number of residues
37  float b = 0;
38  float bfac = residlist[0];
39  int j = 0; //counter CA
40 
41  for(int i=1;i<residlist.Count;i++){
42 
43  if(i+1 == residlist.Count){
44  bfac = b/comp;
45  BfactCAlist.Add (bfac);
46  }
47 
48  if((atomsNameList[i-1] == atomsNameList[i]) && (residlist[i-1] == residlist[i])){
49  if (atomsNameList[i] == "CA"){
50  calist.RemoveAt(j);
51  caChainlist.RemoveAt(j);
52  //Debug.Log ("Remove");
53  }
54  }
55 
56  if(residlist[i-1] == residlist[i]){
57  b += Bfactorlist[i];
58  comp++;
59  }
60 
61  else{
62  bfac = b/comp;
63  BfactCAlist.Add (bfac);
64  j++;
65  b = Bfactorlist[i];
66  comp = 1;
67  }
68  }
69 
70  // Compute bfactor min
72  minValue = float.Parse (minval);
73  else{
74  minValue = GetMin(BfactCAlist);
75  }
76 
77  for(int i=0; i<BfactCAlist.Count;i++)
78  BfactCAlist[i] = BfactCAlist[i] - minValue;
79 
80  // End of bfactor min
81 
82  // Compute Bfactor max
84  maxValue = (float.Parse (maxval) - float.Parse (minval));
85  else{
86  maxValue = GetMax(BfactCAlist);
87  }
88 
89  //bfactor value between 0 and 1
90  for(int i=0; i<BfactCAlist.Count;i++){
91  BfactCAlist[i] = BfactCAlist[i]/maxValue;
92  }
93 
94  GenInterpolationArray_BF geninterpolationarray = new GenInterpolationArray_BF();
95  geninterpolationarray.InputKeyNodes=calist;
96  geninterpolationarray.InputTypeArray=caChainlist;
97  geninterpolationarray.InputBfactArray=BfactCAlist;
98 
99  geninterpolationarray.CalculateSplineArray();
100 
101  calist=null;
102  caChainlist=null;
103  Bfactorlist=null;
104 
105  calist=geninterpolationarray.OutputKeyNodes;
106  caChainlist=geninterpolationarray.OutputTypeArray;
107  Bfactorlist=geninterpolationarray.OutputBfactArray;
108  }
109 
111  MoleculeModel.CaSplineTypeList = new List<AtomModel>();
112 
113  string typebf;
114 
115  for (int k=0; k<calist.Count; k++) {
116  typebf = GetBFStyle(Bfactorlist[k]);
118  }
119 
120  MoleculeModel.CaSplineChainList=caChainlist;
121 
122  if(UIData.ffType == UIData.FFType.HiRERNA)
124  else {
125  //MoleculeModel.bondList=ControlMolecule.CreateBondsList(alist,typelist);
128  }
129  MoleculeModel.atomsnumber = alist.Count;
131  MoleculeModel.CaSplineChainList=caChainlist;
132  minval = minValue.ToString ();
133  maxval = (maxValue+minValue).ToString ();
134  }
135 
136  public static string GetBFStyle(float BFValue){
137  string typebf;
138  if (BFValue < 0.1)
139  typebf = "BF1";
140  else if (BFValue <0.2)
141  typebf = "BF2";
142  else if (BFValue <0.3)
143  typebf = "BF3";
144  else if (BFValue <0.4)
145  typebf = "BF4";
146  else if (BFValue <0.5)
147  typebf = "BF5";
148  else if (BFValue <0.6)
149  typebf = "BF6";
150  else if (BFValue <0.7)
151  typebf = "BF7";
152  else if (BFValue <0.8)
153  typebf = "BF8";
154  else if (BFValue <0.9)
155  typebf = "BF9";
156  else
157  typebf = "BF10";
158  return typebf;
159  }
160 
166  public static float GetMin (List<float> ListValues){
167  float mymin = ListValues[0];
168  foreach (float g in ListValues)
169  if (g<mymin)
170  mymin =g;
171  return mymin;
172  }
173 
179  public static float GetMax (List<float> ListValues){
180  float mymax = ListValues [0];
181  foreach (float f in ListValues)
182  if (f>mymax)
183  mymax =f;
184  return mymax;
185  }
186 
187 }
static List< int[]> CreateBondsList_HiRERNA(List< string > atomnames)
static List< int[]> bondCAList
The bonds between carbon alpha in the CA-Spline.
static List< string > backupCaChainList
Definition: BFactorRep.cs:10
static List< int[]> CreateBondsCAList(List< string > caChainlist)
Creates a bond list for the carbon alpha splines.
static void CreateBFRep()
Definition: BFactorRep.cs:17
static AtomModel GetModel(string type)
Definition: AtomModel.cs:257
static List< int[]> CreateBondsEPList(List< float[]> atomsLocationlist, List< AtomModel > atomsTypelist)
static FFType ffType
Definition: UIData.cs:241
static List< string > atomsNamelist
The name of each atom.
static List< AtomModel > atomsTypelist
The type of each atom.
static float minValue
Definition: BFactorRep.cs:12
static List< int > residueIds
The residue identifiers.
static List< float > backupBfactCAList
Definition: BFactorRep.cs:11
static string maxval
Definition: BFactorRep.cs:15
static List< float > BFactorList
Bfactor of each atom.
static float GetMax(List< float > ListValues)
Find the max value of a list of float.
Definition: BFactorRep.cs:179
static bool isRescale
When true, triggers the B factor value rescaling.
static List< string > backupCaSplineChainList
Sometimes inside pdbs lists are not sorted, and residues mixed So I had to create this list to sort r...
static List< float[]> CaSplineList
The coordinates of each Carbon alpha in the CA-Spline.
static string minval
Definition: BFactorRep.cs:14
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static string GetBFStyle(float BFValue)
Definition: BFactorRep.cs:136
static List< string > CaSplineChainList
The chain of each carbon alpha in the CA-Spline.
static List< float[]> backupCaList
Definition: BFactorRep.cs:9
static List< int[]> bondEPList
The bonds between atoms.
static List< float[]> backupCatomsLocationlist
Backup of the coordinates of each Carbon alpha.
static float GetMin(List< float > ListValues)
Find the min value of a list of float.
Definition: BFactorRep.cs:166
static float maxValue
Definition: BFactorRep.cs:13
static List< AtomModel > CaSplineTypeList
Type of each carbon alpha in the CA-Spline.
Definition: GUIDisplay.cs:66
static List< float[]> atomsLocationlist
The coordinates of each atom.