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