Debian Codegraph @

src/AtomColor.cpp

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
•1 #include <stdio.h>
2
3 #include <map>
4 #include <string>
5 using namespace std;
6
7 static std::map<std::string,float> E2RC; // covalent radius
8 static std::map<std::string,float> E2R; // radius
9 static std::map<std::string,int> E2C; // colors
10
11
12
13 static void InitTables(){
14 if(E2RC.size()==0)
15 {
16 /// according to http://www.umass.edu/microbio/rasmol/rasbonds.htm
17 E2RC[" H"]= 0.320f;
18 E2RC[" C"]= 0.720f;
19 E2RC[" N"]= 0.680f;
20 E2RC[" O"]= 0.680f;
21 E2RC[" P"]= 1.036f;
22 E2RC[" S"]= 1.020f;
23 E2RC["CA"]= 0.992f;
24 E2RC["FE"]= 1.420f;
25 E2RC["ZN"]= 1.448f;
26 E2RC["CD"]= 1.688f; // What is CD anyway?
27 E2RC[" I"]= 1.400f;
28 }
29
30 if(E2R.size()==0)
31 {
32 // according to http://www.imb-jena.de/ImgLibDoc/glossary/IMAGE_VDWR.html
33 //E2R["H"]= 1.20f;
34 //E2R["C"]= 1.70f;
35 //E2R["N"]= 1.55f;
36 //E2R["O"]= 1.52f;
37 E2R[" F"]= 1.47f;
38 //E2R["P"]= 1.80f;
39 //E2R["S"]= 1.80f;
40 E2R["CL"]= 1.89f;
41
42 /// according to http://www.umass.edu/microbio/rasmol/rasbonds.htm
43 E2R[" H"]= 1.100f;
44 E2R[" C"]= 1.548f; // was changed to 1.400 for some reason 1.548 is the reported value
45 E2R[" N"]= 1.400f;
46 E2R[" O"]= 1.348f;
47 E2R[" P"]= 1.880f;
48 E2R[" S"]= 1.808f;
49 E2R["CA"]= 1.948f;
50 E2R["FE"]= 1.948f;
51 E2R["ZN"]= 1.148f;
52 E2R["CD"]= 1.748f;
53 E2R[" I"]= 1.748f;
54 }
55
56 if(E2C.size()==0)
57 {
58 E2C[" H"] = /*[255,255,255]*/ 0xFFFFFF /* 0xFFFFFF */ ;
59 E2C["HE"]= /*[217,255,255]*/ 0xFFC0CB /* 0xD9FFFF */ ;
60 E2C["LI"]= /*[204,128,255]*/ 0xB22222 /* 0xCC80FF */ ;
61 E2C["BE"]= /*[194,255, 0]*/ 0xFF1493 /* 0xC2FF00 */ ;
62 E2C[" B"] = /*[255,181,181]*/ 0x00FF00 /* 0xFFB5B5 */ ;
63 E2C[" C"] = /*[144,144,144]*/ 0x808080 /* 0x909090 */ ;
64 E2C[" N"] = /*[ 48, 80,248]*/ 0x8F8FFF /* 0x3050F8 */ ;
65 E2C[" O"] = /*[255, 13, 13]*/ 0xF00000 /* 0xFF0D0D */ ;
66 E2C[" F"] = /*[144,224, 80]*/ 0xDAA520 /* 0x90E050 */ ;
67 E2C["NE"]= /*[179,227,245]*/ 0xFF1493 /* 0xB3E3F5 */ ;
68 E2C["NA"]= /*[171, 92,242]*/ 0x0000FF /* 0xAB5CF2 */ ;
69 E2C["MG"]= /*[138,255, 0]*/ 0x228B22 /* 0x8AFF00 */ ;
70 E2C["AL"]= /*[191,166,166]*/ 0x808090 /* 0xBFA6A6 */ ;
71 E2C["SI"]= /*[240,200,160]*/ 0xDAA520 /* 0xF0C8A0 */ ;
72 E2C[" P"] = /*[255,128, 0]*/ 0xFFA500 /* 0xFF8000 */ ;
73 E2C[" S"] = /*[255,255, 48]*/ 0xFFC832 /* 0xFFFF30 */ ;
74 E2C["CL"]= /*[ 31,240, 31]*/ 0x00FF00 /* 0x1FF01F */ ;
75 E2C["AR"]= /*[128,209,227]*/ 0xFF1493 /* 0x80D1E3 */ ;
76 E2C["K"] = /*[143, 64,212]*/ 0xFF1493 /* 0x8F40D4 */ ;
77 E2C["CA"]= /*[ 61,255, 0]*/ 0x808090 /* 0x3DFF00 */ ;
78 E2C["SC"]= /*[230,230,230]*/ 0xFF1493 /* 0xE6E6E6 */ ;
79 E2C["TI"]= /*[191,194,199]*/ 0x808090 /* 0xBFC2C7 */ ;
80 E2C[" V"] = /*[166,166,171]*/ 0xFF1493 /* 0xA6A6AB */ ;
81 E2C["CR"]= /*[138,153,199]*/ 0x808090 /* 0x8A99C7 */ ;
82 E2C["MN"]= /*[156,122,199]*/ 0x808090 /* 0x9C7AC7 */ ;
83 E2C["FE"]= /*[224,102, 51]*/ 0xFFA500 /* 0xE06633 */ ;
84 E2C["CO"]= /*[240,144,160]*/ 0xFF1493 /* 0xF090A0 */ ;
85 E2C["NI"]= /*[ 80,208, 80]*/ 0xA52A2A /* 0x50D050 */ ;
86 E2C["CU"]= /*[200,128, 51]*/ 0xA52A2A /* 0xC88033 */ ;
87 E2C["ZN"]= /*[125,128,176]*/ 0xA52A2A /* 0x7D80B0 */ ;
88 E2C["GA"]= /*[194,143,143]*/ 0xFF1493 /* 0xC28F8F */ ;
89 E2C["GE"]= /*[102,143,143]*/ 0xFF1493 /* 0x668F8F */ ;
90 E2C["AS"]= /*[189,128,227]*/ 0xFF1493 /* 0xBD80E3 */ ;
91 E2C["SE"]= /*[255,161, 0]*/ 0xFF1493 /* 0xFFA100 */ ;
92 E2C["BR"]= /*[166, 41, 41]*/ 0xA52A2A /* 0xA62929 */ ;
93 E2C["KR"]= /*[ 92,184,209]*/ 0xFF1493 /* 0x5CB8D1 */ ;
94 E2C["RB"]= /*[112, 46,176]*/ 0xFF1493 /* 0x702EB0 */ ;
95 E2C["SR"]= /*[ 0,255, 0]*/ 0xFF1493 /* 0x00FF00 */ ;
96 E2C[" Y"] = /*[148,255,255]*/ 0xFF1493 /* 0x94FFFF */ ;
97 E2C["ZR"]= /*[148,224,224]*/ 0xFF1493 /* 0x94E0E0 */ ;
98 E2C["NB"]= /*[115,194,201]*/ 0xFF1493 /* 0x73C2C9 */ ;
99 E2C["MO"]= /*[ 84,181,181]*/ 0xFF1493 /* 0x54B5B5 */ ;
100 E2C["TC"]= /*[ 59,158,158]*/ 0xFF1493 /* 0x3B9E9E */ ;
101 E2C["RU"]= /*[ 36,143,143]*/ 0xFF1493 /* 0x248F8F */ ;
102 E2C["RH"]= /*[ 10,125,140]*/ 0xFF1493 /* 0x0A7D8C */ ;
103 E2C["PD"]= /*[ 0,105,133]*/ 0xFF1493 /* 0x006985 */ ;
104 E2C["AG"]= /*[192,192,192]*/ 0x808090 /* 0xC0C0C0 */ ;
105 E2C["CD"]= /*[255,217,143]*/ 0xFF1493 /* 0xFFD98F */ ;
106 E2C["IN"]= /*[166,117,115]*/ 0xFF1493 /* 0xA67573 */ ;
107 E2C["SN"]= /*[102,128,128]*/ 0xFF1493 /* 0x668080 */ ;
108 E2C["SB"]= /*[158, 99,181]*/ 0xFF1493 /* 0x9E63B5 */ ;
109 E2C["TE"]= /*[212,122, 0]*/ 0xFF1493 /* 0xD47A00 */ ;
110 E2C[" I"] = /*[148, 0,148]*/ 0xA020F0 /* 0x940094 */ ;
111 E2C["XE"]= /*[ 66,158,176]*/ 0xFF1493 /* 0x429EB0 */ ;
112 E2C["CS"]= /*[ 87, 23,143]*/ 0xFF1493 /* 0x57178F */ ;
113 E2C["BA"]= /*[ 0,201, 0]*/ 0xFFA500 /* 0x00C900 */ ;
114 E2C["LA"]= /*[112,212,255]*/ 0xFF1493 /* 0x70D4FF */ ;
115 E2C["CE"]= /*[255,255,199]*/ 0xFF1493 /* 0xFFFFC7 */ ;
116 E2C["PR"]= /*[217,255,199]*/ 0xFF1493 /* 0xD9FFC7 */ ;
117 E2C["ND"]= /*[199,255,199]*/ 0xFF1493 /* 0xC7FFC7 */ ;
118 E2C["PM"]= /*[163,255,199]*/ 0xFF1493 /* 0xA3FFC7 */ ;
119 E2C["SM"]= /*[143,255,199]*/ 0xFF1493 /* 0x8FFFC7 */ ;
120 E2C["EU"]= /*[ 97,255,199]*/ 0xFF1493 /* 0x61FFC7 */ ;
121 E2C["GD"]= /*[ 69,255,199]*/ 0xFF1493 /* 0x45FFC7 */ ;
122 E2C["TB"]= /*[ 48,255,199]*/ 0xFF1493 /* 0x30FFC7 */ ;
123 E2C["DY"]= /*[ 31,255,199]*/ 0xFF1493 /* 0x1FFFC7 */ ;
124 E2C["HO"]= /*[ 0,255,156]*/ 0xFF1493 /* 0x00FF9C */ ;
125 E2C["ER"]= /*[ 0,230,117]*/ 0xFF1493 /* 0x00E675 */ ;
126 E2C["TM"]= /*[ 0,212, 82]*/ 0xFF1493 /* 0x00D452 */ ;
127 E2C["YB"]= /*[ 0,191, 56]*/ 0xFF1493 /* 0x00BF38 */ ;
128 E2C["LU"]= /*[ 0,171, 36]*/ 0xFF1493 /* 0x00AB24 */ ;
129 E2C["HF"]= /*[ 77,194,255]*/ 0xFF1493 /* 0x4DC2FF */ ;
130 E2C["TA"]= /*[ 77,166,255]*/ 0xFF1493 /* 0x4DA6FF */ ;
131 E2C[" W"] = /*[ 33,148,214]*/ 0xFF1493 /* 0x2194D6 */ ;
132 E2C["RE"]= /*[ 38,125,171]*/ 0xFF1493 /* 0x267DAB */ ;
133 E2C["OS"]= /*[ 38,102,150]*/ 0xFF1493 /* 0x266696 */ ;
134 E2C["IR"]= /*[ 23, 84,135]*/ 0xFF1493 /* 0x175487 */ ;
135 E2C["PT"]= /*[208,208,224]*/ 0xFF1493 /* 0xD0D0E0 */ ;
136 E2C["AU"]= /*[255,209, 35]*/ 0xDAA520 /* 0xFFD123 */ ;
137 E2C["HG"]= /*[184,184,208]*/ 0xFF1493 /* 0xB8B8D0 */ ;
138 E2C["TL"]= /*[166, 84, 77]*/ 0xFF1493 /* 0xA6544D */ ;
139 E2C["PB"]= /*[ 87, 89, 97]*/ 0xFF1493 /* 0x575961 */ ;
140 E2C["BI"]= /*[158, 79,181]*/ 0xFF1493 /* 0x9E4FB5 */ ;
141 E2C["PO"]= /*[171, 92, 0]*/ 0xFF1493 /* 0xAB5C00 */ ;
142 E2C["AT"]= /*[117, 79, 69]*/ 0xFF1493 /* 0x754F45 */ ;
143 E2C["RN"]= /*[ 66,130,150]*/ 0xFF1493 /* 0x428296 */ ;
144 E2C["FR"]= /*[ 66, 0,102]*/ 0xFF1493 /* 0x420066 */ ;
145 E2C["RA"]= /*[ 0,125, 0]*/ 0xFF1493 /* 0x007D00 */ ;
146 E2C["AC"]= /*[112,171,250]*/ 0xFF1493 /* 0x70ABFA */ ;
147 E2C["TH"]= /*[ 0,186,255]*/ 0xFF1493 /* 0x00BAFF */ ;
148 E2C["PA"]= /*[ 0,161,255]*/ 0xFF1493 /* 0x00A1FF */ ;
149 E2C[" U"] = /*[ 0,143,255]*/ 0xFF1493 /* 0x008FFF */ ;
150 E2C["NP"]= /*[ 0,128,255]*/ 0xFF1493 /* 0x0080FF */ ;
151 E2C["PU"]= /*[ 0,107,255]*/ 0xFF1493 /* 0x006BFF */ ;
152 E2C["AM"]= /*[ 84, 92,242]*/ 0xFF1493 /* 0x545CF2 */ ;
153 E2C["CM"]= /*[120, 92,227]*/ 0xFF1493 /* 0x785CE3 */ ;
154 E2C["BK"]= /*[138, 79,227]*/ 0xFF1493 /* 0x8A4FE3 */ ;
155 E2C["CF"]= /*[161, 54,212]*/ 0xFF1493 /* 0xA136D4 */ ;
156 E2C["ES"]= /*[179, 31,212]*/ 0xFF1493 /* 0xB31FD4 */ ;
157 E2C["FM"]= /*[179, 31,186]*/ 0xFF1493 /* 0xB31FBA */ ;
158 E2C["MD"]= /*[179, 13,166]*/ 0xFF1493 /* 0xB30DA6 */ ;
159 E2C["NO"]= /*[189, 13,135]*/ 0xFF1493 /* 0xBD0D87 */ ;
160 E2C["LR"]= /*[199, 0,102]*/ 0xFF1493 /* 0xC70066 */ ;
161 E2C["RF"]= /*[204, 0, 89]*/ 0xFF1493 /* 0xCC0059 */ ;
162 E2C["DB"]= /*[209, 0, 79]*/ 0xFF1493 /* 0xD1004F */ ;
163 E2C["SG"]= /*[217, 0, 69]*/ 0xFF1493 /* 0xD90045 */ ;
164 E2C["BH"]= /*[224, 0, 56]*/ 0xFF1493 /* 0xE00038 */ ;
165 E2C["HS"]= /*[230, 0, 46]*/ 0xFF1493 /* 0xE6002E */ ;
166 E2C["MT"]= /*[235, 0, 38]*/ 0xFF1493 /* 0xEB0026 */ ;
167 }
168 }
169
•170 static bool addAtomType(const char* namei, int unused, float radius, float radiusC, int r, int g, int b){
171 InitTables();
172
173 // upperCase(name);
174 std::string name(namei);
175 int i=0;
176 while (name[i]) {
177 if ((name[i]>='a') && (name[i]<='z')) name[i]=name[i]-'a'+'A'; //else name[i]=namei[i];
178 i++;
179 }
180
181 if (radius<0.01) radius=0.01;
182 E2R[name]=radius;
183 E2C[name]=(r<<16)+(g<<8)+b;
184 if (radiusC<0.01) radiusC=0.01;
185 E2RC[name]=radiusC;
186 // note: covalent radius does not get updated. If needed,
187
188 #if 0 // write a log of added atom types
189 static FILE* f=NULL;
190 if (f==NULL) { f=fopen("AddedAtomsLog.txt","wt"); };
191 fprintf(f,"Added '%s' %d %f %f (%d %d %d)\n",name,unused,radius,radiusR, r,g,b);
192 fflush(f);
193 #endif
194
195 return true;
196 }
197
198 // Adds Pseudo Atoms types used by NanoDex!
199 static void AddPseudoAtoms(){
200
201 addAtomType("Ax", 200 , 5.0 , 4.0, 102 ,102 , 204 ); // Axis
202 addAtomType("Ae", 204 , 3.5 , 2.5, 102 ,102 , 204 ); // Axis-end
203 addAtomType("Ss", 201 , 4.0 , 3.0, 102 ,204 , 102 ); // Strand sugar
204 addAtomType("Sj", 203 , 4.0 , 3.0, 102 ,204 , 204 ); // Strand junction
205 addAtomType("Pl", 202 , 3.2 , 2.2, 102 ,26 , 128 ); // Phosphorous link
206 addAtomType("Pe", 205 , 3.0 , 2.0, 102 ,26 , 128 ); // Phosphorous end
207 addAtomType("Sh", 206 , 2.5 , 1.5, 102 ,204 , 102 ); // Sugar hydroxyl
208 addAtomType("Hp", 207 , 4.0 , 3.0, 77 ,179 , 77 ); // Hairpin
209 addAtomType(" X", 0 , 1.1 , 0.1, 255*8/10 ,0 ,0 ); // Bondpoint
210 }
211
212 // quick and dirty: reads a line, returns it first 80 chars, skips initial spaces and empty lines
213 static char* getLine(FILE* f){
214 static char res[80];
215 int i=0;
216 while (1) {
217
218 char c=fgetc(f);
219 if (c==EOF) { if (i==0) return NULL; else break;}
220 if (c==13 ) { if (i==0) continue; else break; }
221 if ((i<80) && (c!=10) && ((i!=0) ||(c!=' ')) ) res[i++]=c;
222 }
223 res[i]=0; return res;
224 }
225
226 // reads a NanoDex "art" file, describing custom atom types
227 bool readArtFile(const char* filename){
228 InitTables();
229 AddPseudoAtoms();
230 FILE* f=fopen(filename,"rb");
231 if (!f) return false;
232 while (1) {
233 char* line=getLine(f);
234 if (!line) break;
235 if (line[0]!='#') {
236 char a[100]; int b; float c1,c2; int d,e,f;
237 sscanf(line,"%s %d %f %f %d %d %d",a,&b,&c1,&c2,&d,&e,&f);
238 addAtomType(a,b,c1,c2,d,e,f);
239 }
240 }
241 fclose(f);
242 return true;
243 }
244
245 float getMaxCovelentRadius(){
246 return 1.688f;
247 }
248
249
250
251
252 float getAtomRadius(const char* atomicElementCharP)
253 {
254 InitTables();
255 //std::string ss0,ss1;
256 string atomicElement(atomicElementCharP);
257 //ss0=atomicElement.substr(0,1);
258 //ss1=atomicElement.substr(0,2);
259 float rad=E2R[atomicElement];
260 //if(rad==0) rad = E2R[ss0];
261 if(rad==0) rad=1.5;
262 return rad;
263 }
264
265 float getAtomCovalentRadius(const char* atomicElementCharP){
266 InitTables();
267 //std::string ss0,ss1;
268 string atomicElement(atomicElementCharP);
269 //ss0=atomicElement.substr(0,1);
270 //ss1=atomicElement.substr(0,2);
271 float rad=E2RC[atomicElement];
272
273 //if(rad==0) rad = E2RC[ss0];
274
275 // HACK: covalent (B&S) radius of undefined atoms is defined as half the SpaceFill rad
276 if (rad==0) rad=getAtomRadius(atomicElementCharP)/2.0;
277
278 return rad;
279 }
280
281 int getAtomColor(const char* atomicElementCharP){
282 InitTables();
283 string atomicElement(atomicElementCharP);
284
285 //std::string ss0,ss1,ss2;
286 //size_t last=std::min(atomicElement.length(),atomicElement.find_first_of(' '));
287 //ss0=atomicElement.substr(0,1);
288 int color=E2C[atomicElement];
289 if(color==0)
290 {
291 // printf("color 0 for %s\n",ss0.c_str());
292 //ss1=atomicElement.substr(0,2);
293 //color = 0x000000;
294 }
295
296 return color+0xff000000;
297 }
298
299
300 // VERY QUICK AND DIRTY random color schema computation:
301 // -----------------------------------------------------
302
303 static int basecol=1;
304
305 void ChangeColorSchema(int i){
306 static int index=3;
307 if (i==-1) i=index++;
308
309 basecol=i*1231123;
310 }
311
312 bool tooDark(int c){
313 return (c&255)+ ((c>>8)&255) + ((c>>16)&255) < 200;
314 }
315
316 int getChainColor(int index){
317 int res=basecol*index*35634379;
318 int antiloop=0;
319 while (tooDark(res) && (antiloop++<10) ) {
320 res=(res+1231)*645633737;
321 }
322 return res;
323 }
324