struct atomgrp* join_atomgrps (struct atomgrp** ags) { struct atomgrp* ag = (struct atomgrp*) _mol_calloc (1, sizeof (struct atomgrp)); ag->natoms = 100; // just a guess, realloc as necessary ag->atoms = (struct atom*) _mol_malloc (sizeof (struct atom) * ag->natoms); int agai = 0; // ag atom index int agi = 0; // index into ags while (ags[agi] != NULL) { int agsai; // ags atom index for (agsai = 0; agsai < ags[agi]->natoms; agsai++, agai++) { if (agai+1 > ag->natoms) { ag->natoms *= 2; ag->atoms = (struct atom*) _mol_realloc (ag->atoms, sizeof (struct atom) * ag->natoms); } copy_atom (&ags[agi]->atoms[agsai], &ag->atoms[agai]); } agi++; } // final realloc of the arrays to make them tight ag->natoms = agai; ag->atoms = (struct atom*) _mol_realloc (ag->atoms, sizeof (struct atom) * ag->natoms); return ag; }
bool gcd_get_ucs2( GCD_CCB *ccb, u_i2 length, u_i1 *ptr ) { for( ; length > 0; length--, ptr += sizeof( UCS2 ) ) if ( ! copy_atom( ccb, CV_N_I2_SZ, copy_i2, (u_i1 *)ptr ) ) break; return( ! length ); }
struct atomgrp* copy_atomgrp (struct atomgrp* srcag) { struct atomgrp* destag = (struct atomgrp*) _mol_calloc (1, sizeof (struct atomgrp)); destag->natoms = srcag->natoms; destag->atoms = (struct atom*) _mol_malloc (sizeof (struct atom) * destag->natoms); int atomn; for (atomn = 0; atomn < destag->natoms; atomn++) { copy_atom (&srcag->atoms[atomn], &destag->atoms[atomn]); } return destag; }
struct atomgrp *copy_atomgrp(const struct atomgrp *srcag) { int atomn; struct atomgrp *destag = (struct atomgrp *)_mol_calloc(1, sizeof(struct atomgrp)); destag->natoms = srcag->natoms; destag->atoms = (struct atom *)_mol_calloc(destag->natoms, sizeof(struct atom)); for (atomn = 0; atomn < destag->natoms; atomn++) { copy_atom(&(srcag->atoms[atomn]), &(destag->atoms[atomn])); } return destag; }
struct atomgrp *around(int nlist, int *list, struct atomgrp* ag, double distup) { int i, j; int natoms=ag->natoms; double x1,y1,z1,x2,y2,z2,d2; double du2=distup*distup; int *tmplist; int nout; struct atomgrp *destag; if(natoms==0) { fprintf (stderr, "around> ERROR: no atoms initially"); exit (EXIT_FAILURE); } tmplist=_mol_malloc(natoms*sizeof(int)); for(i=0; i<natoms; i++)tmplist[i]=1; for(i=0; i<nlist; i++)tmplist[list[i]]=0; nout=0; for(i=0; i<nlist; i++) { x1=ag->atoms[list[i]].X; y1=ag->atoms[list[i]].Y; z1=ag->atoms[list[i]].Z; for(j=0; j<natoms; j++) { if(tmplist[j]!=1)continue; x2=ag->atoms[j].X-x1; y2=ag->atoms[j].Y-y1; z2=ag->atoms[j].Z-z1; d2=x2*x2+y2*y2+z2*z2; if(d2<=du2) { tmplist[j]=2; nout++; } } } destag = (struct atomgrp*) _mol_calloc (1, sizeof (struct atomgrp)); destag->natoms = nout; destag->atoms = (struct atom*) _mol_malloc (sizeof (struct atom) * destag->natoms); j=0; for (i = 0; i < natoms; i++) { if(tmplist[i]==2)copy_atom (&ag->atoms[i], &destag->atoms[j++]); } free(tmplist); return destag; }
static gboolean process_header (GMimeObject *object, const char *header, const char *value) { GMimePart *mime_part = (GMimePart *) object; char encoding[32]; guint i; if (g_ascii_strncasecmp (header, "Content-", 8) != 0) return FALSE; for (i = 0; i < G_N_ELEMENTS (content_headers); i++) { if (!g_ascii_strcasecmp (content_headers[i] + 8, header + 8)) break; } switch (i) { case HEADER_CONTENT_TRANSFER_ENCODING: copy_atom (value, encoding, sizeof (encoding) - 1); mime_part->encoding = g_mime_content_encoding_from_string (encoding); break; case HEADER_CONTENT_DESCRIPTION: /* FIXME: we should decode this */ g_free (mime_part->content_description); mime_part->content_description = g_mime_strdup_trim (value); break; case HEADER_CONTENT_LOCATION: g_free (mime_part->content_location); mime_part->content_location = g_mime_strdup_trim (value); break; case HEADER_CONTENT_MD5: g_free (mime_part->content_md5); mime_part->content_md5 = g_mime_strdup_trim (value); break; default: return FALSE; } return TRUE; }
bool gcd_get_f8( GCD_CCB *ccb, u_i1 *ptr ) { return( copy_atom( ccb, CV_N_F8_SZ, copy_f8, (u_i1 *)ptr ) ); }
bool gcd_get_i4( GCD_CCB *ccb, u_i1 *ptr ) { return( copy_atom( ccb, CV_N_I4_SZ, copy_i4, (u_i1 *)ptr ) ); }
bool gcd_get_i1( GCD_CCB *ccb, u_i1 *ptr ) { return( copy_atom( ccb, CV_N_I1_SZ, copy_i1, ptr ) ); }
static int add_h_low(t_atoms **pdbaptr, rvec *xptr[], int nah, t_hackblock ah[], int nterpairs, t_hackblock **ntdb, t_hackblock **ctdb, int *rN, int *rC, gmx_bool bCheckMissing, int **nabptr, t_hack ***abptr, gmx_bool bUpdate_pdba, gmx_bool bKeep_old_pdba) { t_atoms *newpdba = NULL, *pdba = NULL; int nadd; int i, newi, j, d, natoms, nalreadypresent; int *nab = NULL; t_hack **ab = NULL; t_hackblock *hb; rvec *xn; gmx_bool bKeep_ab; /* set flags for adding hydrogens (according to hdb) */ pdba = *pdbaptr; natoms = pdba->nr; if (nabptr && abptr) { /* the first time these will be pointers to NULL, but we will return in them the completed arrays, which we will get back the second time */ nab = *nabptr; ab = *abptr; bKeep_ab = TRUE; if (debug) { fprintf(debug, "pointer to ab found\n"); } } else { bKeep_ab = FALSE; } if (nab && ab) { /* WOW, everything was already figured out */ bUpdate_pdba = FALSE; if (debug) { fprintf(debug, "pointer to non-null ab found\n"); } } else { /* We'll have to do all the hard work */ bUpdate_pdba = TRUE; /* first get all the hackblocks for each residue: */ hb = get_hackblocks(pdba, nah, ah, nterpairs, ntdb, ctdb, rN, rC); if (debug) { dump_hb(debug, pdba->nres, hb); } /* expand the hackblocks to atom level */ snew(nab, natoms); snew(ab, natoms); expand_hackblocks(pdba, hb, nab, ab, nterpairs, rN, rC); free_t_hackblock(pdba->nres, &hb); } if (debug) { fprintf(debug, "before calc_all_pos\n"); dump_ab(debug, natoms, nab, ab, TRUE); } /* Now calc the positions */ calc_all_pos(pdba, *xptr, nab, ab, bCheckMissing); if (debug) { fprintf(debug, "after calc_all_pos\n"); dump_ab(debug, natoms, nab, ab, TRUE); } if (bUpdate_pdba) { /* we don't have to add atoms that are already present in pdba, so we will remove them from the ab (t_hack) */ nadd = check_atoms_present(pdba, nab, ab); if (debug) { fprintf(debug, "removed add hacks that were already in pdba:\n"); dump_ab(debug, natoms, nab, ab, TRUE); fprintf(debug, "will be adding %d atoms\n", nadd); } /* Copy old atoms, making space for new ones */ snew(newpdba, 1); init_t_atoms(newpdba, natoms+nadd, FALSE); newpdba->nres = pdba->nres; sfree(newpdba->resinfo); newpdba->resinfo = pdba->resinfo; } else { nadd = 0; } if (debug) { fprintf(debug, "snew xn for %d old + %d new atoms %d total)\n", natoms, nadd, natoms+nadd); } if (nadd == 0) { /* There is nothing to do: return now */ if (!bKeep_ab) { free_ab(natoms, nab, ab); } return natoms; } snew(xn, natoms+nadd); newi = 0; for (i = 0; (i < natoms); i++) { /* check if this atom wasn't scheduled for deletion */ if (nab[i] == 0 || (ab[i][0].nname != NULL) ) { if (newi >= natoms+nadd) { /*gmx_fatal(FARGS,"Not enough space for adding atoms");*/ nadd += 10; srenew(xn, natoms+nadd); if (bUpdate_pdba) { srenew(newpdba->atom, natoms+nadd); srenew(newpdba->atomname, natoms+nadd); } debug_gmx(); } if (debug) { fprintf(debug, "(%3d) %3d %4s %4s%3d %3d", i+1, newi+1, *pdba->atomname[i], *pdba->resinfo[pdba->atom[i].resind].name, pdba->resinfo[pdba->atom[i].resind].nr, nab[i]); } if (bUpdate_pdba) { copy_atom(pdba, i, newpdba, newi); } copy_rvec((*xptr)[i], xn[newi]); /* process the hacks for this atom */ nalreadypresent = 0; for (j = 0; j < nab[i]; j++) { if (ab[i][j].oname == NULL) /* add */ { newi++; if (newi >= natoms+nadd) { /* gmx_fatal(FARGS,"Not enough space for adding atoms");*/ nadd += 10; srenew(xn, natoms+nadd); if (bUpdate_pdba) { srenew(newpdba->atom, natoms+nadd); srenew(newpdba->atomname, natoms+nadd); } debug_gmx(); } if (bUpdate_pdba) { newpdba->atom[newi].resind = pdba->atom[i].resind; } if (debug) { fprintf(debug, " + %d", newi+1); } } if (ab[i][j].nname != NULL && (ab[i][j].oname == NULL || strcmp(ab[i][j].oname, *newpdba->atomname[newi]) == 0)) { /* add or replace */ if (ab[i][j].oname == NULL && ab[i][j].bAlreadyPresent) { /* This atom is already present, copy it from the input. */ nalreadypresent++; if (bUpdate_pdba) { copy_atom(pdba, i+nalreadypresent, newpdba, newi); } copy_rvec((*xptr)[i+nalreadypresent], xn[newi]); } else { if (bUpdate_pdba) { if (gmx_debug_at) { fprintf(debug, "Replacing %d '%s' with (old name '%s') %s\n", newi, (newpdba->atomname[newi] && *newpdba->atomname[newi]) ? *newpdba->atomname[newi] : "", ab[i][j].oname ? ab[i][j].oname : "", ab[i][j].nname); } snew(newpdba->atomname[newi], 1); *newpdba->atomname[newi] = strdup(ab[i][j].nname); if (ab[i][j].oname != NULL && ab[i][j].atom) /* replace */ { /* newpdba->atom[newi].m = ab[i][j].atom->m; */ /* newpdba->atom[newi].q = ab[i][j].atom->q; */ /* newpdba->atom[newi].type = ab[i][j].atom->type; */ } } if (ab[i][j].bXSet) { copy_rvec(ab[i][j].newx, xn[newi]); } } if (bUpdate_pdba && debug) { fprintf(debug, " %s %g %g", *newpdba->atomname[newi], newpdba->atom[newi].m, newpdba->atom[newi].q); } } } newi++; i += nalreadypresent; if (debug) { fprintf(debug, "\n"); } } } if (bUpdate_pdba) { newpdba->nr = newi; } if (bKeep_ab) { *nabptr = nab; *abptr = ab; } else { /* Clean up */ free_ab(natoms, nab, ab); } if (bUpdate_pdba) { if (!bKeep_old_pdba) { for (i = 0; i < natoms; i++) { /* Do not free the atomname string itself, it might be in symtab */ /* sfree(*(pdba->atomname[i])); */ /* sfree(pdba->atomname[i]); */ } sfree(pdba->atomname); sfree(pdba->atom); sfree(pdba->pdbinfo); sfree(pdba); } *pdbaptr = newpdba; } else { nadd = newi-natoms; } sfree(*xptr); *xptr = xn; return newi; }
int add_h(t_atoms **pdbaptr, rvec *xptr[], int nah, t_hackblock ah[], int nterpairs, t_hackblock **ntdb, t_hackblock **ctdb, int *rN, int *rC, bool bMissing, int **nabptr, t_hack ***abptr, bool bUpdate_pdba, bool bKeep_old_pdba) { t_atoms *newpdba=NULL,*pdba=NULL; bool bSet; int nadd; int i,newi,j,d,natoms; int *nab=NULL; t_hack **ab=NULL; t_hackblock *hb; rvec *xn; bool bKeep_ab; /* set flags for adding hydrogens (according to hdb) */ pdba=*pdbaptr; natoms=pdba->nr; if (nabptr && abptr) { /* the first time these will be pointers to NULL, but we will return in them the completed arrays, which we will get back the second time */ nab = *nabptr; ab = *abptr; bKeep_ab=TRUE; if (debug) fprintf(debug,"pointer to ab found\n"); } else bKeep_ab=FALSE; if (nab && ab) { /* WOW, everything was already figured out */ bUpdate_pdba = FALSE; if (debug) fprintf(debug,"pointer to non-null ab found\n"); } else { /* We'll have to do all the hard work */ bUpdate_pdba = TRUE; /* first get all the hackblocks for each residue: */ hb = get_hackblocks(pdba, nah, ah, nterpairs, ntdb, ctdb, rN, rC); if (debug) dump_hb(debug, pdba->nres, hb); /* expand the hackblocks to atom level */ snew(nab,natoms); snew(ab,natoms); expand_hackblocks(pdba, hb, nab, ab, nterpairs, rN, rC); free_t_hackblock(pdba->nres, &hb); } if (debug) { fprintf(debug,"before calc_all_pos\n"); dump_ab(debug, natoms, nab, ab, TRUE); } /* Now calc the positions */ calc_all_pos(pdba, *xptr, nab, ab, bMissing); if (debug) { fprintf(debug,"after calc_all_pos\n"); dump_ab(debug, natoms, nab, ab, TRUE); } if (bUpdate_pdba) { /* we don't have to add atoms that are already present in pdba, so we will remove them from the ab (t_hack) */ nadd = check_atoms_present(pdba, nab, ab, bMissing); if (debug) { fprintf(debug, "removed add hacks that were already in pdba:\n"); dump_ab(debug, natoms, nab, ab, TRUE); fprintf(debug, "will be adding %d atoms\n",nadd); } /* Copy old atoms, making space for new ones */ snew(newpdba,1); init_t_atoms(newpdba,natoms+nadd,FALSE); newpdba->nres = pdba->nres; sfree(newpdba->resname); newpdba->resname = pdba->resname; } else { nadd = 0; } if (debug) fprintf(debug,"snew xn for %d old + %d new atoms %d total)\n", natoms, nadd, natoms+nadd); snew(xn,natoms+nadd); newi=0; for(i=0; (i<natoms); i++) { /* check if this atom wasn't scheduled for deletion */ if ( nab[i]==0 || (ab[i][0].nname != NULL) ) { if (newi >= natoms+nadd) { /*gmx_fatal(FARGS,"Not enough space for adding atoms");*/ nadd+=10; srenew(xn,natoms+nadd); if (bUpdate_pdba) { srenew(newpdba->atom,natoms+nadd); srenew(newpdba->atomname,natoms+nadd); } debug_gmx(); } if (debug) fprintf(debug,"(%3d) %3d %4s %4s%3d %3d", i+1, newi+1, *pdba->atomname[i], *pdba->resname[pdba->atom[i].resnr], pdba->atom[i].resnr+1, nab[i]); if (bUpdate_pdba) copy_atom(pdba,i, newpdba,newi); copy_rvec((*xptr)[i],xn[newi]); /* process the hacks for this atom */ for(j=0; j<nab[i]; j++) { if ( ab[i][j].oname==NULL ) { /* add */ newi++; if (newi >= natoms+nadd) { /* gmx_fatal(FARGS,"Not enough space for adding atoms");*/ nadd+=10; srenew(xn,natoms+nadd); if (bUpdate_pdba) { srenew(newpdba->atom,natoms+nadd); srenew(newpdba->atomname,natoms+nadd); } debug_gmx(); } if (bUpdate_pdba) { newpdba->atom[newi].resnr=pdba->atom[i].resnr; } if (debug) fprintf(debug," + %d",newi+1); } if ( ab[i][j].nname!=NULL ) { /* add or replace */ if (bUpdate_pdba) { snew(newpdba->atomname[newi],1); *newpdba->atomname[newi]=strdup(ab[i][j].nname); if ( ab[i][j].oname!=NULL && ab[i][j].atom ) { /* replace */ /* newpdba->atom[newi].m = ab[i][j].atom->m; */ /* newpdba->atom[newi].q = ab[i][j].atom->q; */ /* newpdba->atom[newi].type = ab[i][j].atom->type; */ } } bSet=TRUE; for(d=0; d<DIM; d++) bSet = bSet && ab[i][j].newx[d]!=NOTSET; if (bSet) copy_rvec(ab[i][j].newx, xn[newi]); if (bUpdate_pdba && debug) fprintf(debug," %s %g %g",*newpdba->atomname[newi], newpdba->atom[newi].m,newpdba->atom[newi].q); } } newi++; if (debug) fprintf(debug,"\n"); } } if (bUpdate_pdba) newpdba->nr = newi; if ( bKeep_ab ) { *nabptr=nab; *abptr=ab; } else { /* Clean up */ for(i=0; i<natoms; i++) free_t_hack(nab[i], &ab[i]); sfree(nab); sfree(ab); } if ( bUpdate_pdba ) { if ( !bKeep_old_pdba ) { for(i=0; i < natoms; i++) { sfree(*(pdba->atomname[i])); /* sfree(pdba->atomname[i]); */ } sfree(pdba->atomname); sfree(pdba->atom); sfree(pdba->pdbinfo); sfree(pdba); } *pdbaptr=newpdba; } else nadd = newi-natoms; sfree(*xptr); *xptr=xn; return newi; }
token_t akl_lex(struct akl_io_device *dev) { int ch; /* We should take care of the '+', '++', and etc. style functions. Moreover the positive and negative numbers must also work: '(++ +5)' should be valid. */ char op = 0; if (!buffer) init_buffer(); assert(dev); while ((ch = akl_io_getc(dev))) { /* We should avoid the interpretation of the Unix shebang */ if (dev->iod_char_count == 1 && ch == '#') { while ((ch = akl_io_getc(dev)) && ch != '\n') ; } if (ch == EOF) { return tEOF; } else if (ch == '\n') { dev->iod_line_count++; dev->iod_char_count = 0; } else if (ch == '+' || ch == '-') { if (op != 0) { if (op == '+') strcpy(buffer, "++"); else strcpy(buffer, "--"); op = 0; return tATOM; } op = ch; } else if (isdigit(ch)) { akl_io_ungetc(ch, dev); copy_number(dev, op); op = 0; return tNUMBER; } else if (ch == ' ' || ch == '\n') { dev->iod_column = dev->iod_char_count+1; if (op != 0) { if (op == '+') strcpy(buffer, "+"); else strcpy(buffer, "-"); op = 0; return tATOM; } else { continue; } } else if (ch == '"') { ch = akl_io_getc(dev); if (ch == '"') return tNIL; akl_io_ungetc(ch, dev); copy_string(dev); return tSTRING; } else if (ch == '(') { dev->iod_column = dev->iod_char_count+1; ch = akl_io_getc(dev); if (ch == ')') return tNIL; akl_io_ungetc(ch, dev); return tLBRACE; } else if (ch == ')') { return tRBRACE; } else if (ch == '\'' || ch == ':') { return tQUOTE; } else if (ch == ';') { while ((ch = akl_io_getc(dev)) != '\n') { if (akl_io_eof(dev)) return tEOF; } } else if (isalpha(ch) || ispunct(ch)) { akl_io_ungetc(ch, dev); copy_atom(dev); if ((strcasecmp(buffer, "NIL")) == 0) return tNIL; else if ((strcasecmp(buffer, "T")) == 0) return tTRUE; else return tATOM; } else { continue; } } return tEOF; }