/* ------------------------------------------- Copyright 2005-2006 Erik Lechak ------------------------------------------- pdb is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. pdb is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Foobar; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include float atoms[3000][3]; char names[3000][6]; struct map{ char name[7]; void (*handler)(char*); }; char * getString(const char * buffer, int start, int end, char * string){ char *pstring = string; int c; if (strlen(buffer) < end){ *string = '\0'; return string; } for (c=start-1; c<=end-1 ; c++){ if (buffer[c] == ' ' )continue; *(pstring++) = buffer[c]; } *pstring='\0'; return string; } char * getName(const char * buffer, char * name){ getString(buffer,1,7,name); return name; } float getFloat(const char * buffer, int start, int end){ char string[32]; float a; getString(buffer,start,end,string); a = atof(string); //printf("got string '%s' float %f\n", string, a); return a; } int getInt(const char * buffer, int start, int end){ char string[32]; getString(buffer,start,end,string); return atoi(string); } void hATOM(char * buffer){ char atom[5]; char name[7]; float x,y,z; int serial; serial = getInt(buffer, 7,11); atoms[serial][0] = x = getFloat(buffer,31,38); atoms[serial][1] = y = getFloat(buffer,39,46); atoms[serial][2] = z = getFloat(buffer,47,54); getString(buffer,13,14,atom); getString(buffer,13,16,name); strcpy(names[serial], name); printf("diagram %s cd @\n", name); printf(" move %f %f %f\n", x,y,z); printf(" ln /elements/%s %s\n", atom,atom); printf("cd ..\n"); } void hCONECT(char * buffer){ int self; int connection[10]; int c; self = getInt(buffer,7,11); connection[0] = getInt(buffer, 12,16); connection[1] = getInt(buffer, 17,21); connection[2] = getInt(buffer, 22,26); connection[3] = getInt(buffer, 27,31); connection[4] = getInt(buffer, 32,36); connection[5] = getInt(buffer, 27,41); connection[6] = getInt(buffer, 42,46); connection[7] = getInt(buffer, 47,51); connection[8] = getInt(buffer, 52,56); connection[9] = getInt(buffer, 57,61); for (c=0 ; c < 10; c++){ if (! connection[c]) continue; //printf(">>>>>>%i> %i -> %i\n",c, self,connection[c]); printf("shape %s-%s cd @ ",names[self], names[connection[c]]); printf("lines line_width 2 rgb 255 255 255 vertex\n"); printf("%f %f %f %f %f %f\n", atoms[self][0], atoms[self][1], atoms[self][2], atoms[connection[c]][0], atoms[connection[c]][1], atoms[connection[c]][2] ); printf("cd ..\n"); } } struct map handlers[]={ {"ATOM",hATOM}, {"HETATM", hATOM}, {"CONECT", hCONECT}, {"",NULL} }; void callHandler(char * name, char * buffer){ int c=0; while(1){ if (! *(handlers[c].name))break; if ( strcmp(handlers[c].name , name)==0 ) handlers[c].handler(buffer); c++; } } int main(int argc, char **argv){ char buffer[512]; char name[8]; char *pchar; FILE * f; printf("elements.b\n"); printf("window ? cd @ color 255 255 255 \n"); printf("bind <1 mouse motion> rotate_selected\n"); printf("view ? cd @ origin cc bounds 0 0 0 0 -200 200\n"); printf("light light1 cd @ position -30 -30 200 cd ..\n"); if (!( f = fopen(argv[1], "r"))) return 1; if ( (pchar = strrchr(argv[1], '/') )){ pchar++; }else pchar = argv[1]; printf("diagram %s cd @ scale 20 20 20\n", pchar); printf("bind <1 mouse press> select\n"); while(1){ if (! fgets(buffer, 512,f) ) break; if (strlen(buffer) < 6) continue; getName(buffer,name); callHandler(name,buffer); } printf("cd ..\n"); return 0; }