Exemple #1
0
void mk_bonds(int nnm, t_nm2type nmt[],
              t_atoms *atoms, rvec x[], t_params *bond, int nbond[],
              gmx_bool bPBC, matrix box)
{
    t_param b;
    int     i, j;
    t_pbc   pbc;
    rvec    dx;
    real    dx2;

    for (i = 0; (i < MAXATOMLIST); i++)
    {
        b.a[i] = -1;
    }
    for (i = 0; (i < MAXFORCEPARAM); i++)
    {
        b.c[i] = 0.0;
    }

    if (bPBC)
    {
        set_pbc(&pbc, -1, box);
    }
    for (i = 0; (i < atoms->nr); i++)
    {
        if ((i % 10) == 0)
        {
            fprintf(stderr, "\ratom %d", i);
        }
        for (j = i+1; (j < atoms->nr); j++)
        {
            if (bPBC)
            {
                pbc_dx(&pbc, x[i], x[j], dx);
            }
            else
            {
                rvec_sub(x[i], x[j], dx);
            }

            dx2 = iprod(dx, dx);
            if (is_bond(nnm, nmt, *atoms->atomname[i], *atoms->atomname[j],
                        sqrt(dx2)))
            {
                b.AI = i;
                b.AJ = j;
                b.C0 = sqrt(dx2);
                add_param_to_list (bond, &b);
                nbond[i]++;
                nbond[j]++;
                if (debug)
                {
                    fprintf(debug, "Bonding atoms %s-%d and %s-%d\n",
                            *atoms->atomname[i], i+1, *atoms->atomname[j], j+1);
                }
            }
        }
    }
    fprintf(stderr, "\ratom %d\n", i);
}
Exemple #2
0
int mk_specbonds(t_atoms *pdba,rvec x[],gmx_bool bInteractive,
                 t_ssbond **specbonds,gmx_bool bVerbose)
{
    t_specbond *sb=NULL;
    t_ssbond   *bonds=NULL;
    int  nsb;
    int  nspec,nbonds;
    int  *specp,*sgp;
    gmx_bool bDoit,bSwap;
    int  i,j,b,e,e2;
    int  ai,aj,index_sb;
    real **d;
    char buf[10];

    nbonds = 0;
    sb     = get_specbonds(&nsb);

    if (nsb > 0) {
        snew(specp,pdba->nr);
        snew(sgp,pdba->nr);

        nspec = 0;
        for(i=0; (i<pdba->nr); i++) {
            /* Check if this atom is special and if it is not a double atom
             * in the input that still needs to be removed.
             */
            if (is_special(nsb,sb,*pdba->resinfo[pdba->atom[i].resind].name,
                           *pdba->atomname[i]) &&
                    !(nspec > 0 &&
                      pdba->atom[sgp[nspec-1]].resind == pdba->atom[i].resind &&
                      gmx_strcasecmp(*pdba->atomname[sgp[nspec-1]],
                                     *pdba->atomname[i]) == 0)) {
                specp[nspec] = pdba->atom[i].resind;
                sgp[nspec] = i;
                nspec++;
            }
        }
        /* distance matrix d[nspec][nspec] */
        snew(d,nspec);
        for(i=0; (i<nspec); i++)
            snew(d[i],nspec);

        for(i=0; (i<nspec); i++) {
            ai=sgp[i];
            for(j=0; (j<nspec); j++) {
                aj=sgp[j];
                d[i][j]=sqrt(distance2(x[ai],x[aj]));
            }
        }
        if (nspec > 1) {
#define MAXCOL 7
            fprintf(stderr,"Special Atom Distance matrix:\n");
            for(b=0; (b<nspec); b+=MAXCOL) {
                /* print resname/number column headings */
                fprintf(stderr,"%8s%8s","","");
                e=min(b+MAXCOL, nspec-1);
                for(i=b; (i<e); i++) {
                    sprintf(buf,"%s%d",*pdba->resinfo[pdba->atom[sgp[i]].resind].name,
                            pdba->resinfo[specp[i]].nr);
                    fprintf(stderr,"%8s",buf);
                }
                fprintf(stderr,"\n");
                /* print atomname/number column headings */
                fprintf(stderr,"%8s%8s","","");
                e=min(b+MAXCOL, nspec-1);
                for(i=b; (i<e); i++) {
                    sprintf(buf,"%s%d",*pdba->atomname[sgp[i]], sgp[i]+1);
                    fprintf(stderr,"%8s",buf);
                }
                fprintf(stderr,"\n");
                /* print matrix */
                e=min(b+MAXCOL, nspec);
                for(i=b+1; (i<nspec); i++) {
                    sprintf(buf,"%s%d",*pdba->resinfo[pdba->atom[sgp[i]].resind].name,
                            pdba->resinfo[specp[i]].nr);
                    fprintf(stderr,"%8s",buf);
                    sprintf(buf,"%s%d", *pdba->atomname[sgp[i]], sgp[i]+1);
                    fprintf(stderr,"%8s",buf);
                    e2=min(i,e);
                    for(j=b; (j<e2); j++)
                        fprintf(stderr," %7.3f",d[i][j]);
                    fprintf(stderr,"\n");
                }
            }
        }

        snew(bonds,nspec);

        for(i=0; (i<nspec); i++) {
            ai = sgp[i];
            for(j=i+1; (j<nspec); j++) {
                aj = sgp[j];
                if (is_bond(nsb,sb,pdba,ai,aj,d[i][j],&index_sb,&bSwap)) {
                    fprintf(stderr,"%s %s-%d %s-%d and %s-%d %s-%d%s",
                            bInteractive ? "Link" : "Linking",
                            *pdba->resinfo[pdba->atom[ai].resind].name,
                            pdba->resinfo[specp[i]].nr,
                            *pdba->atomname[ai], ai+1,
                            *pdba->resinfo[pdba->atom[aj].resind].name,
                            pdba->resinfo[specp[j]].nr,
                            *pdba->atomname[aj], aj+1,
                            bInteractive ? " (y/n) ?" : "...\n");
                    bDoit=bInteractive ? yesno() : TRUE;

                    if (bDoit) {
                        /* Store the residue numbers in the bonds array */
                        bonds[nbonds].res1 = specp[i];
                        bonds[nbonds].res2 = specp[j];
                        bonds[nbonds].a1   = strdup(*pdba->atomname[ai]);
                        bonds[nbonds].a2   = strdup(*pdba->atomname[aj]);
                        /* rename residues */
                        if (bSwap) {
                            rename_1res(pdba,specp[i],sb[index_sb].newres2,bVerbose);
                            rename_1res(pdba,specp[j],sb[index_sb].newres1,bVerbose);
                        }
                        else {
                            rename_1res(pdba,specp[i],sb[index_sb].newres1,bVerbose);
                            rename_1res(pdba,specp[j],sb[index_sb].newres2,bVerbose);
                        }
                        nbonds++;
                    }
                }
            }
        }

        for(i=0; (i<nspec); i++)
            sfree(d[i]);
        sfree(d);
        sfree(sgp);
        sfree(specp);

        done_specbonds(nsb,sb);
        sfree(sb);
    }

    *specbonds=bonds;

    return nbonds;
}