Пример #1
0
void replace_atom(t_topology *top, int inr, char *anm, char *resnm,
                  real q, real m, int type)
{
    t_atoms *atoms;

    atoms = &(top->atoms);

    /* Replace important properties of an atom by other properties */
    if ((inr < 0) || (inr > atoms->nr))
    {
        gmx_fatal(FARGS, "Replace_atom: inr (%d) not in %d .. %d", inr, 0, atoms->nr);
    }
    if (debug)
    {
        fprintf(debug, "Replacing atom %d ... ", inr);
    }
    /* Charge, mass and type */
    atoms->atom[inr].q    = atoms->atom[inr].qB    = q;
    atoms->atom[inr].m    = atoms->atom[inr].mB    = m;
    atoms->atom[inr].type = atoms->atom[inr].typeB = type;

    /* Residue name */
    atoms->resinfo[atoms->atom[inr].resind].name = put_symtab(&top->symtab, resnm);
    /* Atom name */
    atoms->atomname[inr] = put_symtab(&top->symtab, anm);
    if (debug)
    {
        fprintf(debug, " done\n");
    }
}
Пример #2
0
void copy_atom(t_symtab *tab,t_atoms *a1,int i1,t_atoms *a2,int i2,
	       rvec xin[],rvec xout[],rvec vin[],rvec vout[])
{
  a2->atom[i2]     = a1->atom[i1];
  a2->atomname[i2] = put_symtab(tab,*a1->atomname[i1]);
  a2->resname[a2->atom[i2].resnr] =
    put_symtab(tab,*a1->resname[a1->atom[i1].resnr]);
  copy_rvec(xin[i1],xout[i2]);
  copy_rvec(vin[i1],vout[i2]);
}
Пример #3
0
void add_bond_atomtype(t_bond_atomtype at, t_symtab *tab,
                       char *name)
{
    gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at;

    ga->nr++;
    srenew(ga->atomname, ga->nr);
    ga->atomname[ga->nr-1] = put_symtab(tab, name);
}
Пример #4
0
void gmx_pdb_read_conf(const char *infile,
                       t_topology *top, rvec x[], int *ePBC, matrix box)
{
    FILE *in = gmx_fio_fopen(infile, "r");
    char  title[STRLEN];
    read_pdbfile(in, title, NULL, &top->atoms, &top->symtab, x, ePBC, box, TRUE, NULL);
    top->name = put_symtab(&top->symtab, title);
    gmx_fio_fclose(in);
}
Пример #5
0
void gmx_pdb_read_conf(const char *infile,
                       t_symtab *symtab, char ***name, t_atoms *atoms,
                       rvec x[], int *ePBC, matrix box)
{
    FILE *in = gmx_fio_fopen(infile, "r");
    char  title[STRLEN];
    read_pdbfile(in, title, NULL, atoms, symtab, x, ePBC, box, TRUE, NULL);
    *name = put_symtab(symtab, title);
    gmx_fio_fclose(in);
}
Пример #6
0
static void read_stx_conf(const char *infile, t_topology *top,
                          rvec x[], rvec *v, int *ePBC, matrix box)
{
    FILE       *in;
    t_trxframe  fr;
    int         ftp;
    char        g96_line[STRLEN+1];

    if (top->atoms.nr == 0)
    {
        fprintf(stderr, "Warning: Number of atoms in %s is 0\n", infile);
    }
    else if (top->atoms.atom == NULL)
    {
        gmx_mem("Uninitialized array atom");
    }

    if (ePBC)
    {
        *ePBC = -1;
    }

    ftp = fn2ftp(infile);
    switch (ftp)
    {
        case efGRO:
            gmx_gro_read_conf(infile, top, x, v, box);
            break;
        case efG96:
            fr.title  = NULL;
            fr.natoms = top->atoms.nr;
            fr.atoms  = &top->atoms;
            fr.x      = x;
            fr.v      = v;
            fr.f      = NULL;
            in        = gmx_fio_fopen(infile, "r");
            read_g96_conf(in, infile, &fr, &top->symtab, g96_line);
            gmx_fio_fclose(in);
            copy_mat(fr.box, box);
            top->name = put_symtab(&top->symtab, fr.title);
            sfree(const_cast<char *>(fr.title));
            break;
        case efPDB:
        case efBRK:
        case efENT:
            gmx_pdb_read_conf(infile, top, x, ePBC, box);
            break;
        case efESP:
            gmx_espresso_read_conf(infile, top, x, v, box);
            break;
        default:
            gmx_incons("Not supported in read_stx_conf");
    }
}
Пример #7
0
void t_atoms_set_resinfo(t_atoms *atoms,int atom_ind,t_symtab *symtab,
			 const char *resname,int resnr,unsigned char ic,
			 unsigned char chain)
{
  t_resinfo *ri;

  ri = &atoms->resinfo[atoms->atom[atom_ind].resind];
  ri->name  = put_symtab(symtab,resname);
  ri->nr    = resnr;
  ri->ic    = ic;
  ri->chain = chain;
}
Пример #8
0
static gmx_bool read_atoms(FILE *in, char *line,
                           t_restp *r0, t_symtab *tab, gpp_atomtype_t atype)
{
    int    i, j, cg, maxentries;
    char   buf[256], buf1[256];
    double q;

    /* Read Atoms */
    maxentries   = 0;
    r0->atom     =     NULL;
    r0->atomname = NULL;
    r0->cgnr     =     NULL;
    i            = 0;
    while (get_a_line(in, line, STRLEN) && (strchr(line, '[') == NULL))
    {
        if (sscanf(line, "%s%s%lf%d", buf, buf1, &q, &cg) != 4)
        {
            return FALSE;
        }
        if (i >= maxentries)
        {
            maxentries += 100;
            srenew(r0->atom,     maxentries);
            srenew(r0->atomname, maxentries);
            srenew(r0->cgnr,     maxentries);
        }
        r0->atomname[i] = put_symtab(tab, buf);
        r0->atom[i].q   = q;
        r0->cgnr[i]     = cg;
        j               = get_atomtype_type(buf1, atype);
        if (j == NOTSET)
        {
            gmx_fatal(FARGS, "Atom type %s (residue %s) not found in atomtype "
                      "database", buf1, r0->resname);
        }
        r0->atom[i].type = j;
        r0->atom[i].m    = get_atomtype_massA(j, atype);
        i++;
    }
    r0->natom = i;
    srenew(r0->atom, i);
    srenew(r0->atomname, i);
    srenew(r0->cgnr, i);

    return TRUE;
}
Пример #9
0
int set_atomtype(int nt, gpp_atomtype_t ga, t_symtab *tab,
                 t_atom *a, const char *name, t_param *nb,
                 int bondatomtype,
                 real radius, real vol, real surftens, int atomnumber,
                 real gb_radius, real S_hct)
{
    if ((nt < 0) || (nt >= ga->nr))
    {
        return NOTSET;
    }

    ga->atom[nt]         = *a;
    ga->atomname[nt]     = put_symtab(tab, name);
    ga->nb[nt]           = *nb;
    ga->bondatomtype[nt] = bondatomtype;
    ga->radius[nt]       = radius;
    ga->vol[nt]          = vol;
    ga->surftens[nt]     = surftens;
    ga->atomnumber[nt]   = atomnumber;
    ga->gb_radius[nt]    = gb_radius;
    ga->S_hct[nt]        = S_hct;

    return nt;
}
Пример #10
0
static int read_atom(t_symtab *symtab,
		     char line[],int type,int natom,
		     t_atoms *atoms,rvec x[],bool bChange)
{
  t_atom *atomn;
  int  j,k;
  char nc='\0';
  char anr[12],anm[12],anm_copy[12],altloc,resnm[12],chain[12],resnr[12];
  char xc[12],yc[12],zc[12],occup[12],bfac[12],pdbresnr[12];
  static char oldresnm[12],oldresnr[12];
  int  newres,atomnumber;

  if (natom>=atoms->nr)
    gmx_fatal(FARGS,"\nFound more atoms (%d) in pdb file than expected (%d)",
	      natom+1,atoms->nr);

  /* Skip over type */  
  j=6;
  for(k=0; (k<5); k++,j++) anr[k]=line[j];
  anr[k]=nc;
  trim(anr);
  j++;
  for(k=0; (k<4); k++,j++) anm[k]=line[j];
  anm[k]=nc;
  strcpy(anm_copy,anm);
  atomnumber = NOTSET;
  trim(anm);
  altloc=line[j];
  j++;
  for(k=0; (k<4); k++,j++) 
    resnm[k]=line[j];
  resnm[k]=nc;
  trim(resnm);

  for(k=0; (k<1); k++,j++)
    chain[k]=line[j];
  chain[k]=nc;
  
  for(k=0; (k<4); k++,j++) {
    resnr[k]=line[j];
    pdbresnr[k]=line[j];
  }
  resnr[k]=nc;
  trim(resnr);
  pdbresnr[k]=line[j];
  pdbresnr[k+1]=nc;
  trim(pdbresnr);
  j+=4;

  /* X,Y,Z Coordinate */
  for(k=0; (k<8); k++,j++) xc[k]=line[j];
  xc[k]=nc;
  for(k=0; (k<8); k++,j++) yc[k]=line[j];
  yc[k]=nc;
  for(k=0; (k<8); k++,j++) zc[k]=line[j];
  zc[k]=nc;
  
  /* Weight */
  for(k=0; (k<6); k++,j++) occup[k]=line[j];
  occup[k]=nc;
  
  /* B-Factor */
  for(k=0; (k<7); k++,j++) bfac[k]=line[j];
  bfac[k]=nc;

  if (atoms->atom) {
    atomn=&(atoms->atom[natom]);
    if ((natom==0) || (strcmp(oldresnr,pdbresnr)!=0) || 
	(strcmp(oldresnm,resnm)!=0)) {
      strcpy(oldresnr,pdbresnr);
      strcpy(oldresnm,resnm);
      if (natom==0)
	newres=0;
      else
	newres=atoms->atom[natom-1].resnr+1;
      atoms->nres=newres+1;
      atoms->resname[newres]=put_symtab(symtab,resnm);
    }
    else
      newres=atoms->atom[natom-1].resnr;
    if (bChange)
      xlate_atomname_pdb2gmx(anm); 
    atoms->atomname[natom]=put_symtab(symtab,anm);
    atomn->chain=chain[0];
    atomn->resnr=newres;
    atomn->m = 0.0;
    atomn->q = 0.0;
    atomn->atomnumber = atomnumber;
  }
  x[natom][XX]=atof(xc)*0.1;
  x[natom][YY]=atof(yc)*0.1;
  x[natom][ZZ]=atof(zc)*0.1;
  if (atoms->pdbinfo) {
    atoms->pdbinfo[natom].type=type;
    atoms->pdbinfo[natom].atomnr=atoi(anr);
    atoms->pdbinfo[natom].altloc=altloc;
    strcpy(atoms->pdbinfo[natom].pdbresnr,pdbresnr);
    strcpy(atoms->pdbinfo[natom].atomnm,anm_copy);
    atoms->pdbinfo[natom].bfac=atof(bfac);
    atoms->pdbinfo[natom].occup=atof(occup);
  }
  natom++;
  
  return natom;
}
Пример #11
0
static int read_g96_pos(char line[], t_symtab *symtab,
                        FILE *fp, const char *infile,
                        t_trxframe *fr)
{
    t_atoms   *atoms;
    gmx_bool   bEnd;
    int        nwanted, natoms, atnr, resnr = 0, oldres, newres, shift;
    char       anm[STRLEN], resnm[STRLEN];
    char       c1, c2;
    double     db1, db2, db3;

    nwanted = fr->natoms;

    atoms = fr->atoms;

    natoms = 0;

    if (fr->bX)
    {
        if (fr->bAtoms)
        {
            shift = CHAR_SHIFT;
        }
        else
        {
            shift = 0;
        }
        newres  = -1;
        oldres  = -666; /* Unlikely number for the first residue! */
        bEnd    = FALSE;
        while (!bEnd && fgets2(line, STRLEN, fp))
        {
            bEnd = (strncmp(line, "END", 3) == 0);
            if (!bEnd  && (line[0] != '#'))
            {
                if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
                {
                    gmx_fatal(FARGS, "Did not find 3 coordinates for atom %d in %s\n",
                              natoms+1, infile);
                }
                if ((nwanted != -1) && (natoms >= nwanted))
                {
                    gmx_fatal(FARGS,
                              "Found more coordinates (%d) in %s than expected %d\n",
                              natoms, infile, nwanted);
                }
                if (atoms)
                {
                    if (fr->bAtoms &&
                        (sscanf(line, "%5d%c%5s%c%5s%7d", &resnr, &c1, resnm, &c2, anm, &atnr)
                         != 6))
                    {
                        if (oldres >= 0)
                        {
                            resnr = oldres;
                        }
                        else
                        {
                            resnr    = 1;
                            strncpy(resnm, "???", sizeof(resnm)-1);
                        }
                        strncpy(anm, "???", sizeof(anm)-1);
                    }
                    atoms->atomname[natoms] = put_symtab(symtab, anm);
                    if (resnr != oldres)
                    {
                        oldres = resnr;
                        newres++;
                        if (newres >= atoms->nr)
                        {
                            gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
                                      infile, atoms->nr);
                        }
                        atoms->atom[natoms].resind = newres;
                        if (newres+1 > atoms->nres)
                        {
                            atoms->nres = newres+1;
                        }
                        t_atoms_set_resinfo(atoms, natoms, symtab, resnm, resnr, ' ', 0, ' ');
                    }
                    else
                    {
                        atoms->atom[natoms].resind = newres;
                    }
                }
                if (fr->x)
                {
                    fr->x[natoms][0] = db1;
                    fr->x[natoms][1] = db2;
                    fr->x[natoms][2] = db3;
                }
                natoms++;
            }
        }
        if ((nwanted != -1) && natoms != nwanted)
        {
            fprintf(stderr,
                    "Warning: found less coordinates (%d) in %s than expected %d\n",
                    natoms, infile, nwanted);
        }
    }

    fr->natoms = natoms;

    return natoms;
}
Пример #12
0
void gmx_espresso_read_conf(const char *infile,
                            t_topology *top, rvec x[], rvec *v, matrix box)
{
    t_atoms  *atoms = &top->atoms;
    FILE     *fp;
    char      word[STRLEN], buf[STRLEN];
    int       level, r, nprop, p, i, m, molnr;
    int       prop[32];
    double    d;
    gmx_bool  bFoundParticles, bFoundProp, bFoundVariable, bMol;

    // TODO: The code does not understand titles it writes...
    top->name = put_symtab(&top->symtab, "");

    clear_mat(box);

    fp = gmx_fio_fopen(infile, "r");

    bFoundParticles = FALSE;
    bFoundVariable  = FALSE;
    bMol            = FALSE;
    level           = 0;
    while ((r = get_espresso_word(fp, word)))
    {
        if (level == 1 && std::strcmp(word, "particles") == 0 && !bFoundParticles)
        {
            bFoundParticles = TRUE;
            level          += check_open_parenthesis(fp, r, infile, "particles");
            nprop           = 0;
            while (level == 2 && (r = get_espresso_word(fp, word)))
            {
                bFoundProp = FALSE;
                for (p = 0; p < espNR; p++)
                {
                    if (strcmp(word, esp_prop[p]) == 0)
                    {
                        bFoundProp    = TRUE;
                        prop[nprop++] = p;
                        /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
                    }
                }
                if (!bFoundProp && word[0] != '}')
                {
                    gmx_fatal(FARGS, "Can not read Espresso files with particle property '%s'", word);
                }
                if (bFoundProp && p == espMOLECULE)
                {
                    bMol = TRUE;
                }
                if (r == 3)
                {
                    level--;
                }
            }

            i = 0;
            while (level > 0 && (r = get_espresso_word(fp, word)))
            {
                if (r == 2)
                {
                    level++;
                }
                else if (r == 3)
                {
                    level--;
                }
                if (level == 2)
                {
                    for (p = 0; p < nprop; p++)
                    {
                        switch (prop[p])
                        {
                            case espID:
                                r = get_espresso_word(fp, word);
                                /* Not used */
                                break;
                            case espPOS:
                                for (m = 0; m < 3; m++)
                                {
                                    r = get_espresso_word(fp, word);
                                    sscanf(word, "%lf", &d);
                                    x[i][m] = d;
                                }
                                break;
                            case espTYPE:
                                r                   = get_espresso_word(fp, word);
                                atoms->atom[i].type = std::strtol(word, NULL, 10);
                                break;
                            case espQ:
                                r = get_espresso_word(fp, word);
                                sscanf(word, "%lf", &d);
                                atoms->atom[i].q = d;
                                break;
                            case espV:
                                for (m = 0; m < 3; m++)
                                {
                                    r = get_espresso_word(fp, word);
                                    sscanf(word, "%lf", &d);
                                    v[i][m] = d;
                                }
                                break;
                            case espF:
                                for (m = 0; m < 3; m++)
                                {
                                    r = get_espresso_word(fp, word);
                                    /* not used */
                                }
                                break;
                            case espMOLECULE:
                                r     = get_espresso_word(fp, word);
                                molnr = std::strtol(word, NULL, 10);
                                if (i == 0 ||
                                    atoms->resinfo[atoms->atom[i-1].resind].nr != molnr)
                                {
                                    atoms->atom[i].resind =
                                        (i == 0 ? 0 : atoms->atom[i-1].resind+1);
                                    atoms->resinfo[atoms->atom[i].resind].nr       = molnr;
                                    atoms->resinfo[atoms->atom[i].resind].ic       = ' ';
                                    atoms->resinfo[atoms->atom[i].resind].chainid  = ' ';
                                    atoms->resinfo[atoms->atom[i].resind].chainnum = molnr; /* Not sure if this is right? */
                                }
                                else
                                {
                                    atoms->atom[i].resind = atoms->atom[i-1].resind;
                                }
                                break;
                        }
                    }
                    /* Generate an atom name from the particle type */
                    sprintf(buf, "T%u", atoms->atom[i].type);
                    atoms->atomname[i] = put_symtab(&top->symtab, buf);
                    if (bMol)
                    {
                        if (i == 0 || atoms->atom[i].resind != atoms->atom[i-1].resind)
                        {
                            atoms->resinfo[atoms->atom[i].resind].name =
                                put_symtab(&top->symtab, "MOL");
                        }
                    }
                    else
                    {
                        /* Residue number is the atom number */
                        atoms->atom[i].resind = i;
                        /* Generate an residue name from the particle type */
                        if (atoms->atom[i].type < 26)
                        {
                            sprintf(buf, "T%c", 'A'+atoms->atom[i].type);
                        }
                        else
                        {
                            sprintf(buf, "T%c%c",
                                    'A'+atoms->atom[i].type/26, 'A'+atoms->atom[i].type%26);
                        }
                        t_atoms_set_resinfo(atoms, i, &top->symtab, buf, i, ' ', 0, ' ');
                    }

                    if (r == 3)
                    {
                        level--;
                    }
                    i++;
                }
            }
            atoms->nres = atoms->nr;

            if (i != atoms->nr)
            {
                gmx_fatal(FARGS, "Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms", i, atoms->nr);
            }
        }
        else if (level == 1 && std::strcmp(word, "variable") == 0 && !bFoundVariable)
        {
            bFoundVariable = TRUE;
            level         += check_open_parenthesis(fp, r, infile, "variable");
            while (level == 2 && (r = get_espresso_word(fp, word)))
            {
                if (level == 2 && std::strcmp(word, "box_l") == 0)
                {
                    for (m = 0; m < 3; m++)
                    {
                        r = get_espresso_word(fp, word);
                        sscanf(word, "%lf", &d);
                        box[m][m] = d;
                    }
                    level += check_close_parenthesis(fp, r, infile, "box_l");
                }
            }
        }
        else if (r == 2)
        {
            level++;
        }
        else if (r == 3)
        {
            level--;
        }
    }

    if (!bFoundParticles)
    {
        fprintf(stderr, "Did not find a particles section in Espresso file '%s'\n",
                infile);
    }

    gmx_fio_fclose(fp);
}
Пример #13
0
int main(int argc,char *argv[])
{
  static char *desc[] = {
    "[TT]mkice[tt] generates an ice crystal in the Ih crystal form which is the",
    "most stable form. The rectangular unitcell contains eight molecules",
    "and all oxygens are tetrahedrally coordinated.[PAR]",
    "If an input file is given it is interpreted as a series of oxygen",
    "coordinates the distance between which can be scaled by the odist flag.",
    "The program then adds hydrogens to the oxygens in random orientation",
    "but with proper OH distances and HOH angle. This feature allows to",
    "build water clusters based on oxygen coordinates only."
  };
  static int nx=1,ny=1,nz=1;
  static gmx_bool bYaw=FALSE,bLJ=TRUE,bFull=TRUE,bSeries=FALSE;
  static gmx_bool bOrdered=TRUE,bDiamond=FALSE,bPBC=TRUE;
  static real rcut=0.3,odist=0.274,hdist=0.09572;
  t_pargs pa[] = {
    { "-nx",    FALSE, etINT,  {&nx}, "nx" },
    { "-ny",    FALSE, etINT,  {&ny}, "ny" },
    { "-nz",    FALSE, etINT,  {&nz}, "nz" },
    { "-yaw",   FALSE, etBOOL, {&bYaw},
      "Generate virtual sites and shell positions" },
    { "-lj",    FALSE, etBOOL, {&bLJ},
      "Use LJ as well as coulomb for virial calculation" },
    { "-rcut",  FALSE,etREAL,  {&rcut},"Cut-off for virial calculations" },
    { "-full",  FALSE,etBOOL,  {&bFull},"Full virial output" },
    { "-odist", FALSE, etREAL, {&odist}, "Distance (nm) between oxygens" },
    { "-hdist", FALSE, etREAL, {&hdist}, "Bondlength (nm) for OH bond" },
    { "-diamond",FALSE,etBOOL, {&bDiamond}, "Make a diamond instead" },
    { "-pbc",   FALSE, etBOOL, {&bPBC},  "Make a periodic diamond" },
    { "-order", FALSE,etBOOL,  {&bOrdered}, "Make a proton-ordered ice lattice" },
    { "-series",FALSE, etBOOL, {&bSeries}, 
      "Do a series of virial calculations with different cut-off (from 0.3 up till the specified one)" }
  };
  t_filenm fnm[] = {
    { efSTO, "-p", "ice", ffWRITE },
    { efSTO, "-c", NULL,  ffOPTRD },
    { efDAT, "-f", NULL,  ffOPTRD },
    { efTRN, "-o", "ice", ffOPTWR }
  };
#define NFILE asize(fnm)

  FILE      *fp;
  char      *fn,quote[256];
  int       i,j,k,n,nmax,m,natom,natmol;
  t_atoms   *pdba;
  t_atoms   atoms;
  t_symtab  symtab;
  rvec      box,tmp,*xx;
  matrix    boxje;
  
  CopyRight(stdout,argv[0]);
  parse_common_args(&argc,argv,0,NFILE,fnm,asize(pa),pa,asize(desc),
		    desc,0,NULL);
  if (debug) {
    fprintf(debug,"nx  = %3d, ny  = %3d,  nz   = %3d\n",nx,ny,nz);
    fprintf(debug,"YAW = %3s, LJ  = %3s,  rcut = %g\n",yesno_names[bYaw],
	    yesno_names[bLJ],rcut);
  }

  if (bYaw)
    natmol = 5;
  else if (bDiamond)
    natmol = 1;
  else
    natmol = 3;
    
  if (opt2bSet("-f",NFILE,fnm)) {
    natom = read_rel_coords(opt2fn("-f",NFILE,fnm),&xx,natmol);
    nmax  = natom;
  }
  else {
    natom = natmol*8;
    nmax = natom*nx*ny*nz;
    snew(xx,nmax);
  }
  snew(pdba,1);
  init_t_atoms(pdba,nmax,TRUE);
  pdba->nr = nmax;
  open_symtab(&symtab);
  for(n=0; (n<nmax); n++) {
    pdba->pdbinfo[n].type   = epdbATOM;
    pdba->pdbinfo[n].atomnr = 1+n;
    pdba->atom[n].resnr     = 1+(n/natmol);
    pdba->atomname[n] = put_symtab(&symtab,
				   bDiamond ? diamname[(n % natmol)] : watname[(n % natmol)]);
    if (bDiamond)
      pdba->resname[n] = put_symtab(&symtab,"DIA");
    else
      pdba->resname[n] = put_symtab(&symtab,"SOL");
    sprintf(pdba->pdbinfo[n].pdbresnr,"%d",n);
    pdba->atom[n].chain = ' ';
  }
  
  /* Generate the unit cell */
  if (bDiamond)
    unitcell_d(xx,box,odist); 
  else if (opt2bSet("-f",NFILE,fnm)) {
    random_h_coords(natmol,natom/natmol,xx,box,bYaw,odist,hdist);
  }
  else
    unitcell(xx,box,bYaw,odist,hdist);
  if (debug) {
    clear_mat(boxje);
    boxje[XX][XX] = box[XX];
    boxje[YY][YY] = box[YY];
    boxje[ZZ][ZZ] = box[ZZ];
  }
  n=0;
  for(i=0; (i<nx); i++) {
    tmp[XX] = i*box[XX];
    for(j=0; (j<ny); j++) {
      tmp[YY] = j*box[YY];
      for(k=0; (k<nz); k++) {
	tmp[ZZ] = k*box[ZZ];
	for(m=0; (m<natom); m++,n++) {
	  if ((!bOrdered && ((m % natmol) == 0)) || bOrdered)
	    rvec_add(xx[n % natom],tmp,xx[n]);
	  else
	    ;
	}
      }
    }
  }
    
  clear_mat(boxje);
  boxje[XX][XX] = box[XX]*nx;
  boxje[YY][YY] = box[YY]*ny;
  boxje[ZZ][ZZ] = box[ZZ]*nz;
  
  printf("Crystal:   %10.5f  %10.5f  %10.5f\n",
	 nx*box[XX],ny*box[YY],nz*box[ZZ]);
  
  if (debug && !bDiamond) {
    if (bSeries)
      for(i=3; (i<=10*rcut); i++) {
	fprintf(debug,"This is with rcut = %g\n",i*0.1);
	virial(debug,bFull,nmax/natmol,xx,boxje,
	       0.1*i,bYaw,bYaw ? qyaw : qspc,bLJ);
      }    
    else
      virial(debug,bFull,nmax/natmol,xx,boxje,
	     rcut,bYaw,bYaw ? qyaw : qspc,bLJ);
  }
  
  if (bDiamond) 
    mk_diamond(pdba,xx,odist,&symtab,bPBC,boxje);

  fn = ftp2fn(efSTO,NFILE,fnm);
  if (fn2ftp(fn) == efPDB) {
    fp = gmx_ffopen(fn,"w");
    if (bDiamond)
      fprintf(fp,"HEADER    This is a *diamond*\n");
    else
      fprintf(fp,"HEADER    A beautiful Ice Ih crystal\n");
    fprintf(fp,"REMARK    Generated by mkice with the following options:\n"
	    "REMARK    nx = %d, ny = %d, nz = %d, odist = %g, hdist = %g\n",
	    nx,ny,nz,odist,hdist);
	bromacs(quote,255);
    write_pdbfile(fp,quote,pdba,xx,boxje,' ',-1);
    gmx_ffclose(fp);
  }
  else {
    bromacs(quote,255);
    write_sto_conf(fn,quote,pdba,xx,NULL,boxje);
  }
  
  if (ftp2bSet(efTRN,NFILE,fnm))
    write_trn(ftp2fn(efTRN,NFILE,fnm),0,0,0,boxje,nmax,xx,NULL,NULL);
	       
  return 0;
}
Пример #14
0
static void mk_diamond(t_atoms *a,rvec x[],real odist,t_symtab *symtab,
		       gmx_bool bPBC,matrix box)
{
  
  int   i,ib,j,k,l,m,nrm=0;
  t_bbb *bbb;
  gmx_bool  *bRemove;
  rvec  dx;
  
  do {
    nrm = 0;
    bbb = mk_bonds(a->nr,x,odist,bPBC,box);
    
    for(i=0; (i<a->nr); i++) {
      if (bbb[i].n < 2) {
	for(k=0; (k<bbb[i].n); k++) {
	  ib = bbb[i].aa[k];
	  for(j=0; (j<bbb[ib].n); j++)
	    if (bbb[ib].aa[j] == i)
	      break;
	  if (j == bbb[ib].n)
	    gmx_fatal(FARGS,"Bond inconsistency (%d not in list of %d)!\n",i,ib);
	  for( ; (j<bbb[ib].n-1); j++)
	    bbb[ib].aa[j] = bbb[ib].aa[j+1];
	  bbb[ib].n--;
	  nrm++;
	}
	bbb[i].n = 0;
      }
    }
  
    for(i=j=0; (i<a->nr); i++) {
      if (bbb[i].n >= 2) {
	copy_rvec(x[i],x[j]);
	j++;
      }
    }
    fprintf(stderr,"Kicking out %d carbon atoms (out of %d)\n",
	    a->nr-j,a->nr);
    a->nr = j;
    sfree(bbb);
  } while (nrm > 0);
  /* Rename atoms */
  bbb = mk_bonds(a->nr,x,odist,bPBC,box);
  for(i=0; (i<a->nr); i++) {
    switch (bbb[i].n) {
    case 4:
      a->atomname[i] = put_symtab(symtab,"C");
      break;
    case 3:
      a->atomname[i] = put_symtab(symtab,"CH1");
      break;
    case 2:
      a->atomname[i] = put_symtab(symtab,"CH2");
      break;
    default:
      gmx_fatal(FARGS,"This atom (%d) has %d bonds only",i,bbb[i].n);
    }
  }
  sfree(bbb);
}
Пример #15
0
static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                           t_symtab *symtab, t_atoms *atoms, int *ndec,
                           rvec x[], rvec *v, matrix box)
{
    char       name[6];
    char       line[STRLEN+1], *ptr;
    char       buf[256];
    double     x1, y1, z1, x2, y2, z2;
    rvec       xmin, xmax;
    int        natoms, i, m, resnr, newres, oldres, ddist, c;
    gmx_bool   bFirst, bVel;
    char      *p1, *p2, *p3;

    newres  = -1;
    oldres  = NOTSET; /* Unlikely number for the first residue! */
    ddist   = 0;

    /* Read the title and number of atoms */
    get_coordnum_fp(in, title, &natoms);

    if (natoms > atoms->nr)
    {
        gmx_fatal(FARGS, "gro file contains more atoms (%d) than expected (%d)",
                  natoms, atoms->nr);
    }
    else if (natoms <  atoms->nr)
    {
        fprintf(stderr, "Warning: gro file contains less atoms (%d) than expected"
                " (%d)\n", natoms, atoms->nr);
    }

    bFirst = TRUE;

    bVel = FALSE;

    /* just pray the arrays are big enough */
    for (i = 0; (i < natoms); i++)
    {
        if ((fgets2 (line, STRLEN, in)) == NULL)
        {
            gmx_fatal(FARGS, "Unexpected end of file in file %s at line %d",
                      infile, i+2);
        }
        if (strlen(line) < 39)
        {
            gmx_fatal(FARGS, "Invalid line in %s for atom %d:\n%s", infile, i+1, line);
        }

        /* determine read precision from distance between periods
           (decimal points) */
        if (bFirst)
        {
            bFirst = FALSE;
            p1     = strchr(line, '.');
            if (p1 == NULL)
            {
                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
            }
            p2 = strchr(&p1[1], '.');
            if (p2 == NULL)
            {
                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
            }
            ddist = p2 - p1;
            *ndec = ddist - 5;

            p3 = strchr(&p2[1], '.');
            if (p3 == NULL)
            {
                gmx_fatal(FARGS, "A coordinate in file %s does not contain a '.'", infile);
            }

            if (p3 - p2 != ddist)
            {
                gmx_fatal(FARGS, "The spacing of the decimal points in file %s is not consistent for x, y and z", infile);
            }
        }

        /* residue number*/
        memcpy(name, line, 5);
        name[5] = '\0';
        sscanf(name, "%d", &resnr);
        memcpy(name, line+5, 5);
        name[5] = '\0';
        if (resnr != oldres)
        {
            oldres = resnr;
            newres++;
            if (newres >= natoms)
            {
                gmx_fatal(FARGS, "More residues than atoms in %s (natoms = %d)",
                          infile, natoms);
            }
            atoms->atom[i].resind = newres;
            t_atoms_set_resinfo(atoms, i, symtab, name, resnr, ' ', 0, ' ');
        }
        else
        {
            atoms->atom[i].resind = newres;
        }

        /* atomname */
        memcpy(name, line+10, 5);
        atoms->atomname[i] = put_symtab(symtab, name);

        /* eventueel controle atomnumber met i+1 */

        /* coordinates (start after residue data) */
        ptr = line + 20;
        /* Read fixed format */
        for (m = 0; m < DIM; m++)
        {
            for (c = 0; (c < ddist && ptr[0]); c++)
            {
                buf[c] = ptr[0];
                ptr++;
            }
            buf[c] = '\0';
            if (sscanf (buf, "%lf %lf", &x1, &x2) != 1)
            {
                gmx_fatal(FARGS, "Something is wrong in the coordinate formatting of file %s. Note that gro is fixed format (see the manual)", infile);
            }
            else
            {
                x[i][m] = x1;
            }
        }

        /* velocities (start after residues and coordinates) */
        if (v)
        {
            /* Read fixed format */
            for (m = 0; m < DIM; m++)
            {
                for (c = 0; (c < ddist && ptr[0]); c++)
                {
                    buf[c] = ptr[0];
                    ptr++;
                }
                buf[c] = '\0';
                if (sscanf (buf, "%lf", &x1) != 1)
                {
                    v[i][m] = 0;
                }
                else
                {
                    v[i][m] = x1;
                    bVel    = TRUE;
                }
            }
        }
    }
    atoms->nres = newres + 1;

    /* box */
    fgets2 (line, STRLEN, in);
    if (sscanf (line, "%lf%lf%lf", &x1, &y1, &z1) != 3)
    {
        gmx_warning("Bad box in file %s", infile);

        /* Generate a cubic box */
        for (m = 0; (m < DIM); m++)
        {
            xmin[m] = xmax[m] = x[0][m];
        }
        for (i = 1; (i < atoms->nr); i++)
        {
            for (m = 0; (m < DIM); m++)
            {
                xmin[m] = min(xmin[m], x[i][m]);
                xmax[m] = max(xmax[m], x[i][m]);
            }
        }
        for (i = 0; i < DIM; i++)
        {
            for (m = 0; m < DIM; m++)
            {
                box[i][m] = 0.0;
            }
        }
        for (m = 0; (m < DIM); m++)
        {
            box[m][m] = (xmax[m]-xmin[m]);
        }
        fprintf(stderr, "Generated a cubic box %8.3f x %8.3f x %8.3f\n",
                box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
    }
    else
    {
        /* We found the first three values, the diagonal elements */
        box[XX][XX] = x1;
        box[YY][YY] = y1;
        box[ZZ][ZZ] = z1;
        if (sscanf (line, "%*f%*f%*f%lf%lf%lf%lf%lf%lf",
                    &x1, &y1, &z1, &x2, &y2, &z2) != 6)
        {
            x1 = y1 = z1 = x2 = y2 = z2 = 0.0;
        }
        box[XX][YY] = x1;
        box[XX][ZZ] = y1;
        box[YY][XX] = z1;
        box[YY][ZZ] = x2;
        box[ZZ][XX] = y2;
        box[ZZ][YY] = z2;
    }

    return bVel;
}
Пример #16
0
static void read_espresso_conf(char *infile,
			       t_atoms *atoms,rvec x[],rvec *v,matrix box)
{
  static t_symtab *symtab=NULL;
  FILE *fp;
  char word[STRLEN],buf[STRLEN];
  int  natoms,level,npar,r,nprop,p,i,m;
  int  prop[32];
  double d;
  bool bFoundParticles,bFoundProp,bFoundVariable,bMol;

  if (!symtab) {
    snew(symtab,1);
    open_symtab(symtab);
  }

  clear_mat(box);
  
  fp = gmx_fio_fopen(infile,"r");
  
  bFoundParticles = FALSE;
  bFoundVariable = FALSE;
  bMol = FALSE;
  level = 0;
  while ((r=get_espresso_word(fp,word))) {
    if (level==1 && strcmp(word,"particles")==0 && !bFoundParticles) {
      bFoundParticles = TRUE;
      level += check_open_parenthesis(fp,r,infile,"particles");
      nprop = 0;
      while (level == 2 && (r=get_espresso_word(fp,word))) {
	bFoundProp = FALSE;
	for(p=0; p<espNR; p++) {
	  if (strcmp(word,esp_prop[p]) == 0) {
	    bFoundProp = TRUE;
	    prop[nprop++] = p;
	    /* printf("  prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
	  }
	}
	if (!bFoundProp && word[0] != '}') {
	  gmx_fatal(FARGS,"Can not read Espresso files with particle property '%s'",word);
	}
	if (bFoundProp && p == espMOLECULE)
	  bMol = TRUE;
	if (r == 3)
	  level--;
      }
      
      i = 0;
      while (level > 0 && (r=get_espresso_word(fp,word))) {
	if (r == 2) {
	  level++;
	} else if (r == 3) {
	  level--;
	}
	if (level == 2) {
	  for(p=0; p<nprop; p++) {
	    switch (prop[p]) {
	    case espID:
	      r = get_espresso_word(fp,word);
	      /* Not used */
	      break;
	    case espPOS:
	      for(m=0; m<3; m++) {
		r = get_espresso_word(fp,word);
		sscanf(word,"%lf",&d);
		x[i][m] = d;
	      }
	      break;
	    case espTYPE:
	      r = get_espresso_word(fp,word);
	      atoms->atom[i].type = atoi(word);
	      break;
	    case espQ:
	      r = get_espresso_word(fp,word);
	      sscanf(word,"%lf",&d);
	      atoms->atom[i].q = d;
	      break;
	    case espV:
	      for(m=0; m<3; m++) {
		r = get_espresso_word(fp,word);
		sscanf(word,"%lf",&d);
		v[i][m] = d;
	      }
	      break;
	    case espF:
	      for(m=0; m<3; m++) {
		r = get_espresso_word(fp,word);
		/* not used */
	      }
	      break;
	    case espMOLECULE:
	      r = get_espresso_word(fp,word);
	      atoms->atom[i].resnr = atoi(word);
	      break;
	    }
	  }
	  /* Generate an atom name from the particle type */
	  sprintf(buf,"T%d",atoms->atom[i].type);
	  atoms->atomname[i] = put_symtab(symtab,buf);
	  if (bMol) {
	    if (i == 0 || atoms->atom[i].resnr != atoms->atom[i-1].resnr) {
	      atoms->resname[atoms->atom[i].resnr] = put_symtab(symtab,"MOL");
	    }
	  } else {
	    /* Residue number is the atom number */
	    atoms->atom[i].resnr = i;
	    /* Generate an residue name from the particle type */
	    if (atoms->atom[i].type < 26) {
	      sprintf(buf,"T%c",'A'+atoms->atom[i].type);
	    } else {
	      sprintf(buf,"T%c%c",
		      'A'+atoms->atom[i].type/26,'A'+atoms->atom[i].type%26);
	    }
	    atoms->resname[atoms->atom[i].resnr] = put_symtab(symtab,buf);
	  }	  

	  if (r == 3)
	    level--;
	  i++;
	}
      }
      atoms->nres = atoms->nr;

      if (i != atoms->nr) {
	gmx_fatal(FARGS,"Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms",i,atoms->nr);
      }
    } else if (level==1 && strcmp(word,"variable")==0 && !bFoundVariable) {
      bFoundVariable = TRUE;
      level += check_open_parenthesis(fp,r,infile,"variable");
      while (level==2 && (r=get_espresso_word(fp,word))) {
	if (level==2 && strcmp(word,"box_l") == 0) {
	  for(m=0; m<3; m++) {
	    r = get_espresso_word(fp,word);
	    sscanf(word,"%lf",&d);
	    box[m][m] = d;
	  }
	  level += check_close_parenthesis(fp,r,infile,"box_l");
	}
      }
    } else if (r == 2) {
      level++;
    } else if (r == 3) {
      level--;
    }
  }
  
  if (!bFoundParticles) {
    fprintf(stderr,"Did not find a particles section in Espresso file '%s'\n",
	    infile);
  }
  
  gmx_fio_fclose(fp);
}
Пример #17
0
static int read_atom(t_symtab *symtab,
                     char line[], int type, int natom,
                     t_atoms *atoms, rvec x[], int chainnum, gmx_bool bChange)
{
    t_atom       *atomn;
    int           j, k;
    char          nc = '\0';
    char          anr[12], anm[12], anm_copy[12], altloc, resnm[12], rnr[12], elem[3];
    char          xc[12], yc[12], zc[12], occup[12], bfac[12];
    unsigned char resic;
    char          chainid;
    int           resnr, atomnumber;

    if (natom >= atoms->nr)
    {
        gmx_fatal(FARGS, "\nFound more atoms (%d) in pdb file than expected (%d)",
                  natom+1, atoms->nr);
    }

    /* Skip over type */
    j = 6;
    for (k = 0; (k < 5); k++, j++)
    {
        anr[k] = line[j];
    }
    anr[k] = nc;
    trim(anr);
    j++;
    for (k = 0; (k < 4); k++, j++)
    {
        anm[k] = line[j];
    }
    anm[k] = nc;
    std::strcpy(anm_copy, anm);
    rtrim(anm_copy);
    atomnumber = 0;
    trim(anm);
    altloc = line[j];
    j++;
    for (k = 0; (k < 4); k++, j++)
    {
        resnm[k] = line[j];
    }
    resnm[k] = nc;
    trim(resnm);

    chainid = line[j];
    j++;

    for (k = 0; (k < 4); k++, j++)
    {
        rnr[k] = line[j];
    }
    rnr[k] = nc;
    trim(rnr);
    resnr = std::strtol(rnr, NULL, 10);
    resic = line[j];
    j    += 4;

    /* X,Y,Z Coordinate */
    for (k = 0; (k < 8); k++, j++)
    {
        xc[k] = line[j];
    }
    xc[k] = nc;
    for (k = 0; (k < 8); k++, j++)
    {
        yc[k] = line[j];
    }
    yc[k] = nc;
    for (k = 0; (k < 8); k++, j++)
    {
        zc[k] = line[j];
    }
    zc[k] = nc;

    /* Weight */
    for (k = 0; (k < 6); k++, j++)
    {
        occup[k] = line[j];
    }
    occup[k] = nc;

    /* B-Factor */
    for (k = 0; (k < 7); k++, j++)
    {
        bfac[k] = line[j];
    }
    bfac[k] = nc;

    /* 10 blanks */
    j += 10;

    /* Element name */
    for (k = 0; (k < 2); k++, j++)
    {
        elem[k] = line[j];
    }
    elem[k] = nc;
    trim(elem);

    if (atoms->atom)
    {
        atomn = &(atoms->atom[natom]);
        if ((natom == 0) ||
            atoms->resinfo[atoms->atom[natom-1].resind].nr != resnr ||
            atoms->resinfo[atoms->atom[natom-1].resind].ic != resic ||
            (strcmp(*atoms->resinfo[atoms->atom[natom-1].resind].name, resnm) != 0))
        {
            if (natom == 0)
            {
                atomn->resind = 0;
            }
            else
            {
                atomn->resind = atoms->atom[natom-1].resind + 1;
            }
            atoms->nres = atomn->resind + 1;
            t_atoms_set_resinfo(atoms, natom, symtab, resnm, resnr, resic, chainnum, chainid);
        }
        else
        {
            atomn->resind = atoms->atom[natom-1].resind;
        }
        if (bChange)
        {
            xlate_atomname_pdb2gmx(anm);
        }
        atoms->atomname[natom] = put_symtab(symtab, anm);
        atomn->m               = 0.0;
        atomn->q               = 0.0;
        atomn->atomnumber      = atomnumber;
        strncpy(atomn->elem, elem, 4);
    }
    x[natom][XX] = strtod(xc, NULL)*0.1;
    x[natom][YY] = strtod(yc, NULL)*0.1;
    x[natom][ZZ] = strtod(zc, NULL)*0.1;
    if (atoms->pdbinfo)
    {
        atoms->pdbinfo[natom].type   = type;
        atoms->pdbinfo[natom].atomnr = strtol(anr, NULL, 10);
        atoms->pdbinfo[natom].altloc = altloc;
        strcpy(atoms->pdbinfo[natom].atomnm, anm_copy);
        atoms->pdbinfo[natom].bfac  = strtod(bfac, NULL);
        atoms->pdbinfo[natom].occup = strtod(occup, NULL);
    }
    natom++;

    return natom;
}
Пример #18
0
void rename_atoms(const char *xlfile,const char *ffdir,
                  t_atoms *atoms,t_symtab *symtab,const t_restp *restp,
                  gmx_bool bResname,gmx_residuetype_t rt,gmx_bool bReorderNum,
                  gmx_bool bVerbose)
{
    FILE *fp;
    int nxlate,a,i,resind;
    t_xlate_atom *xlatom;
    int  nf;
    char **f;
    char c,*rnm,atombuf[32],*ptr0,*ptr1;
    gmx_bool bReorderedNum,bRenamed,bMatch;

    nxlate = 0;
    xlatom = NULL;
    if (xlfile != NULL)
    {
        fp = libopen(xlfile);
        get_xlatoms(xlfile,fp,&nxlate,&xlatom);
        fclose(fp);
    }
    else
    {
        nf = fflib_search_file_end(ffdir,".arn",FALSE,&f);
        for(i=0; i<nf; i++)
        {
            fp = fflib_open(f[i]);
            get_xlatoms(f[i],fp,&nxlate,&xlatom);
            fclose(fp);
            sfree(f[i]);
        }
        sfree(f);
    }

    for(a=0; (a<atoms->nr); a++)
    {
        resind = atoms->atom[a].resind;
        if (bResname)
        {
            rnm = *(atoms->resinfo[resind].name);
        }
        else
        {
            rnm = *(atoms->resinfo[resind].rtp);
        }
               
        strcpy(atombuf,*(atoms->atomname[a]));
        bReorderedNum = FALSE;
        if (bReorderNum)
        {
            if (isdigit(atombuf[0]))
            {
                c = atombuf[0];
                for (i=0; ((size_t)i<strlen(atombuf)-1); i++)
                {
                    atombuf[i] = atombuf[i+1];
                }
                atombuf[i] = c;
                bReorderedNum = TRUE;
            }
        }
        bRenamed = FALSE;
        for(i=0; (i<nxlate) && !bRenamed; i++) {
            /* Check if the base file name of the rtp and arn entry match */
            if (restp == NULL ||
                gmx_strcasecmp(restp[resind].filebase,xlatom[i].filebase) == 0)
            {
                /* Match the residue name */
                bMatch = (xlatom[i].res == NULL ||
                          (gmx_strcasecmp("protein",xlatom[i].res) == 0 &&
                           gmx_residuetype_is_protein(rt,rnm)) ||
                          (gmx_strcasecmp("DNA",xlatom[i].res) == 0 &&
                           gmx_residuetype_is_dna(rt,rnm)) ||
                          (gmx_strcasecmp("RNA",xlatom[i].res) == 0 &&
                           gmx_residuetype_is_rna(rt,rnm)));
                if (!bMatch)
                {
                    ptr0 = rnm;
                    ptr1 = xlatom[i].res;
                    while (ptr0[0] != '\0' && ptr1[0] != '\0' &&
                           (ptr0[0] == ptr1[0] || ptr1[0] == '?'))
                    {
                        ptr0++;
                        ptr1++;
                    }
                    bMatch = (ptr0[0] == '\0' && ptr1[0] == '\0');
                }
                if (bMatch && strcmp(atombuf,xlatom[i].atom) == 0)
                {
                    /* We have a match. */
                    /* Don't free the old atomname,
                     * since it might be in the symtab.
                     */
                    ptr0 = strdup(xlatom[i].replace);
                    if (bVerbose)
                    {
                        printf("Renaming atom '%s' in residue %d %s to '%s'\n",
                               *atoms->atomname[a],
                               atoms->resinfo[resind].nr,
                               *atoms->resinfo[resind].name,
                               ptr0);
                    }
                    atoms->atomname[a] = put_symtab(symtab,ptr0);
                    bRenamed = TRUE;
                }
            }
        }
        if (bReorderedNum && !bRenamed)
        {
            atoms->atomname[a] = put_symtab(symtab,atombuf);
        }
    }

    done_xlatom(nxlate,xlatom);
}
Пример #19
0
void connelly_plot(const char *fn,int ndots,real dots[],rvec x[],t_atoms *atoms,
		   t_symtab *symtab,int ePBC,matrix box,gmx_bool bSave)
{
  static const char *atomnm="DOT";
  static const char *resnm ="DOT";
  static const char *title ="Connely Dot Surface Generated by g_sas";

  int  i,i0,r0,ii0,k;
  rvec *xnew;
  t_atoms aaa;

  if (bSave) {  
    i0 = atoms->nr;
    r0 = atoms->nres;
    srenew(atoms->atom,atoms->nr+ndots);
    srenew(atoms->atomname,atoms->nr+ndots);
    srenew(atoms->resinfo,r0+1);
    atoms->atom[i0].resind = r0;
    t_atoms_set_resinfo(atoms,i0,symtab,resnm,r0+1,' ',0,' ');
    srenew(atoms->pdbinfo,atoms->nr+ndots);
    snew(xnew,atoms->nr+ndots);
    for(i=0; (i<atoms->nr); i++)
      copy_rvec(x[i],xnew[i]);
    for(i=k=0; (i<ndots); i++) {
      ii0 = i0+i;
      atoms->atomname[ii0] = put_symtab(symtab,atomnm);
      atoms->pdbinfo[ii0].type = epdbATOM;
      atoms->pdbinfo[ii0].atomnr= ii0;
      atoms->atom[ii0].resind = r0;
      xnew[ii0][XX] = dots[k++];
      xnew[ii0][YY] = dots[k++];
      xnew[ii0][ZZ] = dots[k++];
      atoms->pdbinfo[ii0].bfac  = 0.0;
      atoms->pdbinfo[ii0].occup = 0.0;
    }
    atoms->nr   = i0+ndots;
    atoms->nres = r0+1;
    write_sto_conf(fn,title,atoms,xnew,NULL,ePBC,box);
    atoms->nres = r0;
    atoms->nr   = i0;
  }
  else {
    init_t_atoms(&aaa,ndots,TRUE);
    aaa.atom[0].resind = 0;
    t_atoms_set_resinfo(&aaa,0,symtab,resnm,1,' ',0,' ');
    snew(xnew,ndots);
    for(i=k=0; (i<ndots); i++) {
      ii0 = i;
      aaa.atomname[ii0] = put_symtab(symtab,atomnm);
      aaa.pdbinfo[ii0].type = epdbATOM;
      aaa.pdbinfo[ii0].atomnr= ii0;
      aaa.atom[ii0].resind = 0;
      xnew[ii0][XX] = dots[k++];
      xnew[ii0][YY] = dots[k++];
      xnew[ii0][ZZ] = dots[k++];
      aaa.pdbinfo[ii0].bfac  = 0.0;
      aaa.pdbinfo[ii0].occup = 0.0;
    }
    aaa.nr = ndots;
    write_sto_conf(fn,title,&aaa,xnew,NULL,ePBC,box);
    do_conect(fn,ndots,xnew);
    free_t_atoms(&aaa,FALSE);
  }
  sfree(xnew);
}