예제 #1
0
static void clean_dih(t_param *dih, int *ndih,t_param idih[],int nidih,
		      t_atoms *atoms,bool bAlldih, bool bRemoveDih)
{
  int  i,j,k,l;
  int  *index,nind;
  bool bIsSet,bKeep;
  int  bestl,nh,minh;
  
  snew(index,*ndih+1);
  if (bAlldih) {
    fprintf(stderr,"Keeping all generated dihedrals\n");
    nind = *ndih;
    for(i=0; i<nind; i++) 
      index[i] = i;
    index[nind] = *ndih;
  } else {
    /* Make an index of all dihedrals over each bond */
    nind = 0;
    for(i=0; i<*ndih; i++) 
      if (!remove_dih(dih,i,*ndih)) 
	index[nind++]=i;
    index[nind] = *ndih;
  }

  /* if we don't want all dihedrals, we need to select the ones with the 
   *  fewest hydrogens
   */
  
  k=0;
  for(i=0; i<nind; i++) {
    bIsSet = (dih[index[i]].c[MAXFORCEPARAM-1] != NOTSET);
    bKeep = TRUE;
    if (!bIsSet && bRemoveDih)
      /* remove the dihedral if there is an improper on the same bond */
      for(j=0; (j<nidih) && bKeep; j++)
	bKeep = !deq(&dih[index[i]],&idih[j]);

    if (bKeep) {
      /* Now select the "fittest" dihedral:
       * the one with as few hydrogens as possible 
       */
      
      /* Best choice to get dihedral from */
      bestl=index[i];
      if (!bAlldih && !bIsSet) {
	/* Minimum number of hydrogens for i and l atoms */
	minh=2;
	for(l=index[i]; (l<index[i+1]) && deq(&dih[index[i]],&dih[l]); l++) {
	  if ((nh=n_hydro(dih[l].a,atoms->atomname)) < minh) {
	    minh=nh;
	    bestl=l;
	  }
	  if (minh == 0)
	    break;
	}
      }
      if (k != bestl)
	cpparam(&(dih[k]),&dih[bestl]);
      k++;
    }
  }

  for (i=k; i<*ndih; i++)
    strcpy(dih[i].s,"");
  *ndih = k;

  sfree(index);
}
예제 #2
0
파일: gen_ad.cpp 프로젝트: tanigawa/gromacs
/* Clean up the dihedrals (both generated and read from the .rtp
 * file). */
static void clean_dih(t_param *dih, int *ndih, t_param improper[], int nimproper,
                      t_atoms *atoms, gmx_bool bKeepAllGeneratedDihedrals,
                      gmx_bool bRemoveDihedralIfWithImproper)
{
    int   i, j, k, l;
    int  *index, nind;

    /* Construct the list of the indices of the dihedrals
     * (i.e. generated or read) that might be kept. */
    snew(index, *ndih+1);
    if (bKeepAllGeneratedDihedrals)
    {
        fprintf(stderr, "Keeping all generated dihedrals\n");
        nind = *ndih;
        for (i = 0; i < nind; i++)
        {
            index[i] = i;
        }
        index[nind] = *ndih;
    }
    else
    {
        nind = 0;
        /* Check if generated dihedral i should be removed. The
         * dihedrals have been sorted by dcomp() above, so all those
         * on the same two central atoms are together, with those from
         * the .rtp file preceding those that were automatically
         * generated. We remove the latter if the former exist. */
        for (i = 0; i < *ndih; i++)
        {
            /* Keep the dihedrals that were defined in the .rtp file,
             * and the dihedrals that were generated and different
             * from the last one (whether it was generated or not). */
            if (was_dihedral_set_in_rtp(&dih[i]) ||
                0 == i ||
                !is_dihedral_on_same_bond(&dih[i], &dih[i-1]))
            {
                index[nind++] = i;
            }
        }
        index[nind] = *ndih;
    }

    k = 0;
    for (i = 0; i < nind; i++)
    {
        gmx_bool bWasSetInRTP = was_dihedral_set_in_rtp(&dih[index[i]]);
        gmx_bool bKeep        = TRUE;
        if (!bWasSetInRTP && bRemoveDihedralIfWithImproper)
        {
            /* Remove the dihedral if there is an improper on the same
             * bond. */
            for (j = 0; j < nimproper && bKeep; j++)
            {
                bKeep = !is_dihedral_on_same_bond(&dih[index[i]], &improper[j]);
            }
        }

        if (bKeep)
        {
            /* If we don't want all dihedrals, we want to select the
             * ones with the fewest hydrogens. Note that any generated
             * dihedrals on the same bond as an .rtp dihedral may have
             * been already pruned above in the construction of
             * index[]. However, their parameters are still present,
             * and l is looping over this dihedral and all of its
             * pruned siblings. */
            int bestl = index[i];
            if (!bKeepAllGeneratedDihedrals && !bWasSetInRTP)
            {
                /* Minimum number of hydrogens for i and l atoms */
                int minh = 2;
                for (l = index[i];
                     (l < index[i+1] &&
                      is_dihedral_on_same_bond(&dih[index[i]], &dih[l]));
                     l++)
                {
                    int nh = n_hydro(dih[l].a, atoms->atomname);
                    if (nh < minh)
                    {
                        minh  = nh;
                        bestl = l;
                    }
                    if (0 == minh)
                    {
                        break;
                    }
                }
            }
            if (k != bestl)
            {
                cpparam(&dih[k], &dih[bestl]);
            }
            k++;
        }
    }

    for (i = k; i < *ndih; i++)
    {
        strcpy(dih[i].s, "");
    }
    *ndih = k;

    sfree(index);
}