예제 #1
0
파일: read_pcm.c 프로젝트: fzahari/ParFit
void pcmfin(int nth,int isubred)
{
        unsigned int   substrismin;
        int             newatom, i, ibondcount, ibonded, ibondorder,
                        icoord, imetcount, ioffset, ispin, iprint,
                        isubmap[MAXSS], j, numbonds, niatom;
        int            newat, newtype, ifile, isMetal, biotype, itype;
        long int       mask;
        char           ianame[3];
        float          ddcount, xtmp, ytmp, ztmp;
        FILE           *pcminfile;

        imetcount = 0;
        isMetal = FALSE;
        ddcount = 0;
        substrismin = False;
        fxtor.nfxtor = 0;
        pcmfile.nocaps = False;
        numbonds = 0;
        ibondcount = 0;
	newatom = 0;
	newtype = 0;

        for (i = 0; i < MAXSS; i++) 
        {
                isubmap[i] = 0;
        }

       ioffset = 0;

        pcminfile = fopen_path(Openbox.path,Openbox.fname,"r");
         
        if (pcminfile == NULL)
        {
                message_alert("Error Opening PCM file","PCM Setup");
                fprintf(pcmoutfile,"PCMFIN error opening file %d %s\n",nth,Openbox.fname);
                return;
        }
        
        if (default_intype != MMX)
            read_atomtypes(default_intype);

        ifile = 0;
        if (nth != 1)
        {
                while ( FetchRecord(pcminfile,pcmfile.string) )
                {
                        if (strncasecmp(pcmfile.string,"{PCM",4) == 0)
                        {
                                ifile++;
                                if (ifile == nth)
                                        break;
                        }
                }
        }else
        {
                FetchRecord(pcminfile,pcmfile.string);
        }

/*  finished scaning to starting structure  now read file */
        if (isubred == 0)
        {
                sscanf(pcmfile.string, "{PCM %60c", Struct_Title);
                clean_string(Struct_Title);
        } else
        {
                if (natom < 1 )
                {
                        sscanf(pcmfile.string, "{PCM %60c", Struct_Title);
                        clean_string(Struct_Title);
                }   
        }
L_30:
        FetchRecord(pcminfile,pcmfile.string);
        *(pcmfile.string + strlen(pcmfile.string) ) = '\0';
        if (feof(pcminfile))
                goto L_170;
        pcmfile.head = 1;
        NL;
L_40:
        if (strcmp(pcmfile.token, "NA") == 0) 
        {
                gettoken();
                if (pcmfile.head == 1000)
                        goto L_30;
                niatom = atoi(pcmfile.token);
                if (niatom + ioffset > MAXATOM) 
                {
                        natom = ioffset;
                        fclose(pcminfile);
                        message_alert(" Maximum number of atoms exceeded in PCMFIN","PCM Setup");
                        fprintf(pcmoutfile," unable to continue reading, more than Max atoms %d\n",MAXATOM);
                        return;
                }
                niatom += ioffset;
                NL;
                goto L_30;
        } else if (strcmp(pcmfile.token,"ATOMTYPES") == 0)
        {
            gettoken();
            if (pcmfile.head == 1000)
               goto L_30;
            default_intype = atoi(pcmfile.token);
            read_atomtypes(default_intype);
            NL;
            goto L_30;
        }  else if (strcmp(pcmfile.token, "NT") == 0)  /* This is for Amino Acids */
        {
                NL;
                i = atoi(pcmfile.token);                /* i is atom number of N terminus */
                mask = 1L << NTERM;                         /* use bit 0 of substr 1 for N terminus*/
                atom[i+ioffset].flags |= mask;

                NL;
                if (strcmp(pcmfile.token, "CT") == 0)
                {
                        NL;
                        i = atoi(pcmfile.token);        /* i is atom number of C terminus  */
                        mask = 1L << CNTERM;                /* use bit 1 of substr 1 for C terminus */
                        atom[i+ioffset].flags |= mask;
                }
        }  else if (strcmp(pcmfile.token, "5PRIME") == 0)  /* This is for Nucleic Acids */
        {
                NL;
                i = atoi(pcmfile.token);                    /* i is atom number of 5prime terminus */
                mask = 1L << P5;                        
                atom[i+ioffset].flags |= mask;
        }else if (strcmp(pcmfile.token, "3PRIME") == 0)  /* This is for Nucleic Acids */
        {
                NL;
                i = atoi(pcmfile.token);        /* i is atom number of C terminus  */
                mask = 1L << P3;                /* use bit 1 of substr 1 for C terminus */
                atom[i+ioffset].flags |= mask;
        }  else if (strcmp(pcmfile.token, "FG") == 0)  /* This is for functional groups */
        {
                NL;
                i = atoi(pcmfile.token);                /* i is atom number of connect point */
                mask = 1L << DUMMY;                         /* use bit 0 of substr 1 for connect*/
                atom[i+ioffset].flags |= mask;

        }  else if (strcmp(pcmfile.token, "OT") == 0)   /*  This is for Sugars  */
        {
                NL;
                i = atoi(pcmfile.token);                /* i is atom number of O terminus */
                mask = 1L << NTERM;                                 /* use bit 0 of substr 1 for O terminus*/
                atom[i+ioffset].flags |= mask;

                NL;
                if (strcmp(pcmfile.token, "CT") == 0)
                {
                        NL;
                        i = atoi(pcmfile.token);        /* i is atom number of H terminus  */
                        mask = 1L << CNTERM;                         /* use bit 1 of substr 1 for H terminus */
                        atom[i+ioffset].flags |= mask;
                }

                NL;
                if (strcmp(pcmfile.token, "OTWO") == 0)
                {
                        NL;
                        i = atoi(pcmfile.token);        /* i is atom number of H terminus  */
                        oh2 = i+ioffset;
                }

                NL;
                if (strcmp(pcmfile.token, "OTHR") == 0)
                {
                        NL;
                        i = atoi(pcmfile.token);        /* i is atom number of H terminus  */
                        oh3 = i+ioffset;
                }

                NL;
                if (strcmp(pcmfile.token, "OSIX") == 0)
                {
                        NL;
                        i = atoi(pcmfile.token);        /* i is atom number of H terminus  */
                        oh6 = i+ioffset;
                }
        } else if (strcmp(pcmfile.token,"START") == 0) /* flag for polybuild */
        {
                NL;
                i = atoi(pcmfile.token);
                mask = 1L << DUMMY;
                atom[i+ioffset].flags |= mask;
                NL;   // END
                NL;
                i = atoi(pcmfile.token);
                mask = 1L << DUMMY;
                atom[i+ioffset].flags |= mask;
        } else if  (strcmp(pcmfile.token,"NMOL") == 0)
        {
            NL;
            NL;
            NL;
            NL;
            NL;
            NL;
            NL;
            goto L_30;
        } else if (strcmp(pcmfile.token, "OPT") == 0)
        {
            NL;  // para
            NL;
            optimize_data.param_avail = atoi(pcmfile.token);                   
            NL; // conv
            NL;
            optimize_data.converge = atoi(pcmfile.token);                   
            NL;  // ie
            NL;
            optimize_data.initial_energy = atof(pcmfile.token);                   
            NL;  // fe
            NL;
            optimize_data.final_energy = atof(pcmfile.token);                   
            NL;   // iH
            NL;
            optimize_data.initial_heat = atof(pcmfile.token);
            NL; // fH             
            NL;
            optimize_data.final_heat = atof(pcmfile.token);                   
            goto L_30;
        }  else if (strcmp(pcmfile.token, "SS") == 0)
        {
                goto L_30;
        }  else if (strcmp(pcmfile.token, "AT") == 0) 
        {
                NL;
                newat = atoi(pcmfile.token);   // atom serial number
                if (newat + ioffset > MAXATOM) 
                {
                        message_alert(" Maximum number of atoms exceeded in PCMFIN at atom read","PCM Setup");
                        fprintf(pcmoutfile,"atom read %d %d %d\n",newat,ioffset,natom);
                        natom = ioffset + newat - 1;
                        fclose(pcminfile);
                        exit(0);
                }
                newat += ioffset;
                NL;
                if (isdigit(*pcmfile.token)) 
                {
                        newtype = atoi(pcmfile.token);
                }       else   // character string for metal atom
                {
                        strcpy(ianame,pcmfile.token);
                        isMetal = TRUE;
                        i = strlen(ianame);
                        if ( i == 2) 
                            ianame[1] = tolower(ianame[1]);
                }
                NL;
                xtmp = atof(pcmfile.token);
                NL;
                ytmp = (atof(pcmfile.token));
                NL;
                ztmp = atof(pcmfile.token);
                NL;
                if (isMetal == FALSE)
                {
                    itype = newtype;
                    get_atomname(newtype,ianame);
                    if (default_intype == MM3)
                       itype = mm3_mmxtype(newtype);
                    else if (default_intype == MMFF94)
                       itype = mmff_mmxtype(newtype);
                       
                    newatom = make_atom(newtype, xtmp, ytmp, ztmp,ianame);
                    if (default_intype == MM3)
                        set_atomtype(newatom, itype,newtype,0,0,0);
                    else if (default_intype == MMFF94)
                        set_atomtype(newatom, itype,0,newtype,0,0);
                }else if (isMetal == TRUE)
                {
                    newatom = make_atom(0, xtmp, ytmp, ztmp,ianame);
                    isMetal = FALSE;
                }

L_90:
                if (strcmp(pcmfile.token, "B") == 0) 
                {
                        /* Reading bonds now */
                        NL;
                        j = 0;
        L_100:
                        j += 1;
                        if (pcmfile.state == NUMERIC) 
                        {
                                ibonded = atoi(pcmfile.token);
                                ibonded += ioffset;
                        } else 
                        {
                                goto L_90;
                        }
                        NL;
                        if (pcmfile.state == NUMERIC) 
                        {
                                ibondorder = atoi(pcmfile.token);
                        } else 
                        {
                                fprintf(stdout, "missing a bondorder, assuming 1\n");
                                goto L_40;
                        }
                        if (newatom < ibonded)
                                make_bond(newatom, ibonded, ibondorder);
                        if (ibondorder == 9)
                        {
                                atom[newatom].flags |= (1L << METCOORD_MASK);
                                atom[ibonded].flags |= (1L << METCOORD_MASK);
                        }       
                        NL;
                        goto L_100;
                }else if ( strcmp(pcmfile.token, "P")== 0)
                {
                        atom[newatom].flags |= (1L << PI_MASK);
                        NL;
                        goto L_90;
                }else if (strcmp(pcmfile.token, "D") == 0)   // biomolecule marking
                {
                        NL;
                        biotype = atoi(pcmfile.token);
                        atom[newatom].biotype =  biotype;                       
                        NL;
                        goto L_90;
                }else if (strcmp(pcmfile.token,"M")==0)
                {
                        NL;
                        icoord = atoi(pcmfile.token);
                        if (icoord == 0)
                        {
                                atom[newatom].flags |= (1L << SATMET_MASK);
                        } else if (icoord == 2)
                        {
                                atom[newatom].flags |= (1L << GT18e_MASK);
                        } else{
                                atom[newatom].flags |= (1L << GT18e_MASK);
                                atom[newatom].flags |= (1L << SATMET_MASK);
                        }
                        NL;
                        if (pcmfile.state != 1)
                                goto L_90;
                        ispin = atoi(pcmfile.token);
                        if (ispin == 0)
                        {
                                atom[newatom].flags |= (1L << LOWSPIN_MASK);
                        } else if (ispin == 1) 
                        {
                                atom[newatom].flags |= (1L << SQPLAN_MASK);
                        } else 
                        {
                                atom[newatom].flags |= (1L << LOWSPIN_MASK);
                                atom[newatom].flags |= (1L << SQPLAN_MASK);
                        }
                        NL;
                        goto L_90;
                }else if (strcmp(pcmfile.token,"S")== 0)
                {
                        NL;
                        if (pcmfile.state == NUMERIC)
                        {
                                j = atoi(pcmfile.token);
                                mask = (1L << j);
                                NL;
                                goto L_90;
                        } else
                        {
                                goto L_90;
                        }
                }else if (strcmp(pcmfile.token,"H")== 0)
                {
                        atom[newatom].flags |= (1L << HBOND_MASK);
                        NL;
                        goto L_90;
                }else if (strcmp(pcmfile.token,"C")==0)
                {
                        NL;
                        atom[newatom].charge = atof(pcmfile.token);
                        NL;
                        goto L_90;
                } else if (strcmp(pcmfile.token,"ML") == 0)
                {
                    NL;
                    j = atoi(pcmfile.token);
                    atom[newatom].molecule = j;
                    goto L_90;
                }else if (strcmp(pcmfile.token,"R")== 0)
                {
                        NL;
                        atom[newatom].radius = atof(pcmfile.token);
                        NL;
                        goto L_90;
                }               
        } else if (strncasecmp(pcmfile.token, "}",1) == 0) 
        {
                goto L_170;             /* end of structure */
        }  else if (strcmp(pcmfile.token, "FL") == 0) 
        {
                NL;
L_120:          if (strcmp(pcmfile.token, "PRINT") == 0) 
                {
                        iprint = 1;
                        NL;
                        if (pcmfile.state == ALPHABETIC)
                                goto L_120;
                        iprint = atoi(pcmfile.token);
                        NL;
                        goto L_120;
                } else if (strcmp(pcmfile.token, "DIELC") == 0) 
                {
                        NL;
                        if (pcmfile.state != 1)
                                goto L_120;
//                        units.dielec = atof(pcmfile.token);
                        NL;
                        goto L_120;
                } else if (strcmp(pcmfile.token, "UV") == 0) 
                {
                        NL;             
                        if (pcmfile.state != 1)
                                goto L_120;
                        pistuf.iuv = atoi(pcmfile.token);
                        NL;
                        goto L_120;
                } else if (strcmp(pcmfile.token, "PIPR") == 0) 
                {
                        NL;             
                        if (pcmfile.state != 1)
                                goto L_120;
                        pistuf.jprint = atoi(pcmfile.token);
                        NL;
                        goto L_120;
                } else if (strcmp(pcmfile.token, "PIPL") == 0) 
                {
                        NL;             
                        if (pcmfile.state != 1)
                                goto L_120;
                        pistuf.nplane = atoi(pcmfile.token);
                        NL;
                        goto L_120;
                } else if (strcmp(pcmfile.token, "EINT") == 0) 
                {
                        NL;             
                        if (pcmfile.state != 1)
                                goto L_120;
                        minim_values.ndc = atoi(pcmfile.token);
                        NL;
                        goto L_120;
                }
        }  else if (strcmp(pcmfile.token, "CO") == 0) 
        {
        } else if (strcmp(pcmfile.token, "FBND") == 0)
        {
                NL;
                ts_bondorder.fbnd[0] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[1] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[2] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[3] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[4] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[5] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[6] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[7] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[8] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[9] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[10] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[11] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[12] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[13] = atof(pcmfile.token);
                NL;
                ts_bondorder.fbnd[14] = atof(pcmfile.token);
        }  else if (strcmp(pcmfile.token, "FIX") == 0) 
        {
                NL;
                if (strcmp(pcmfile.token, "DIS") == 0) 
                {
                        NL;
                        fixdis.ifxstr[fixdis.nfxstr][0] = atoi(pcmfile.token);
                        NL;
                        fixdis.ifxstr[fixdis.nfxstr][1] = atoi(pcmfile.token);
                        NL;
L_1223:                 if (strcmp(pcmfile.token, "R") == 0) 
                        {
                                NL;
                                fixdis.fxstrd[fixdis.nfxstr] = atof(pcmfile.token);
                                NL;
                                goto L_1223;
                        } else if (strcmp(pcmfile.token, "K") == 0) 
                        {
                                NL;
                                fixdis.fxstrc[fixdis.nfxstr] = atof(pcmfile.token);
                                fixdis.nfxstr +=1;
                                NL;
                                goto L_1223;
                        }
                }
        }  else if (strcmp(pcmfile.token, "DD") == 0) 
        {
                if (isubred == 1)
                        goto L_30;

                NL;
                
                if (pcmfile.state == NUMERIC)
                {
                    fxtor.iatom[fxtor.nfxtor][0] = atoi(pcmfile.token);
                    NL;
                    fxtor.iatom[fxtor.nfxtor][1] = atoi(pcmfile.token);
                    NL;
                    fxtor.iatom[fxtor.nfxtor][2] = atoi(pcmfile.token);
                    NL;
                    fxtor.iatom[fxtor.nfxtor][3] = atoi(pcmfile.token);
                    NL;
L_150:              if (strcmp(pcmfile.token, "FROM") == 0)
                    {
                       NL;
                       fxtor.start_ang[fxtor.nfxtor] = atoi(pcmfile.token);
                       fxtor.curr_ang[fxtor.nfxtor] = fxtor.start_ang[fxtor.nfxtor];
                       NL;
                       goto L_150;
                    } else if (strcmp(pcmfile.token, "TO") == 0)
                    {
                       NL;
                       fxtor.final_ang[fxtor.nfxtor] = atoi(pcmfile.token);
                       NL;
                       goto L_150;
                    } else if (strcmp(pcmfile.token, "BY") == 0)
                    {
                       NL;
                       fxtor.step[fxtor.nfxtor] = atoi(pcmfile.token);
                       fxtor.nfxtor++;
                       NL;
                       goto L_150;                       
                    }
                }
        } 
        goto L_30;
L_170:
        fclose(pcminfile);
        for (i=1; i <= natom; i++)
        {
                if (atom[i].mmx_type == 5)
                {
                        flags.noh = True;
                        break;
                }
        }
        if (default_intype != MMX)
           read_atomtypes(MMX);
        return;
} 
예제 #2
0
파일: molecule.c 프로젝트: cogitokat/brlcad
/* File format from stdin
 *
 * For a ATOM DATA_TYPE ATOM_ID ATOM_NAME RED GREEN BLUE
 * For a Sphere DATA_TYPE SPH_ID CENTER (X, Y, Z) RADIUS ATOM_TYPE
 * For a Bond   DATA_TYPE SPH_ID SPH_ID
 * DATA_TYPE = 0 - Atom1 - Sphere 2 - Bond
 * SPH_ID = integer
 * CENTER = three float values x, y, z
 * RADIUS = Float
 * ATOM_TYPE = integer
 * ATOM_NAME = Character pointer to name value.
 */
void
read_data(void)
{

    int data_type;
    int sphere_id;
    point_t center;
    float x, y, z;
    float sphere_radius;
    int atom_type;
    int b_1, b_2;
    int red, green, blue;
    int i = 0;
    int ret;

    while (scanf(" %d", &data_type) != 0) {

	switch (data_type) {
	    case (0):
		ret = scanf("%d", &i);
		if (ret == 0)
		    perror("scanf");
		if (i < 0 || i >= 50) {
		    fprintf(stderr, "Atom index value %d is out of bounds [0,50)\n", i);
		    return;
		}
		ret = scanf("%128s", atom_list[i].a_name);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%d", &red);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%d", &green);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%d", &blue);
		if (ret == 0)
		    perror("scanf");
		atom_list[i].red  = red;
		atom_list[i].green  = green;
		atom_list[i].blue  = blue;
		break;
	    case (1):
		ret = scanf("%d", &sphere_id);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%f", &x);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%f", &y);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%f", &z);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%f", &sphere_radius);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%d", &atom_type);
		if (ret == 0)
		    perror("scanf");
		VSET(center, x, y, z);
		process_sphere(sphere_id, center, sphere_radius,
			       atom_type);
		break;
	    case (2):
		ret = scanf("%d", &b_1);
		if (ret == 0)
		    perror("scanf");
		ret = scanf("%d", &b_2);
		if (ret == 0)
		    perror("scanf");
		(void)make_bond(b_1, b_2);
		break;
	    default:
	    case (4):
		return;
	}
    }
}