77 VPRIVATE char *MCxmlwhiteChars = " =,;\t\n\r<>";
87 VPRIVATE int readFlatFileLine(Vio *sock, Vparam_AtomData *atom);
97 VPRIVATE int readXMLFileAtom(Vio *sock, Vparam_AtomData *atom);
100 #if !defined(VINLINE_VPARAM)
102 VPUBLIC unsigned long int Vparam_memChk(Vparam *thee) {
103 if (thee == VNULL) return 0;
104 return Vmem_bytes(thee->vmem);
107 #endif /* if !defined(VINLINE_VPARAM) */
109 VPUBLIC Vparam_AtomData* Vparam_AtomData_ctor() {
111 Vparam_AtomData *thee = VNULL;
113 /* Set up the structure */
114 thee = (Vparam_AtomData*)Vmem_malloc(VNULL, 1, sizeof(Vparam_AtomData) );
115 VASSERT(thee != VNULL);
116 VASSERT(Vparam_AtomData_ctor2(thee));
121 VPUBLIC int Vparam_AtomData_ctor2(Vparam_AtomData *thee) { return 1; }
123 VPUBLIC void Vparam_AtomData_dtor(Vparam_AtomData **thee) {
125 if ((*thee) != VNULL) {
126 Vparam_AtomData_dtor2(*thee);
127 Vmem_free(VNULL, 1, sizeof(Vparam_AtomData), (void **)thee);
133 VPUBLIC void Vparam_AtomData_dtor2(Vparam_AtomData *thee) { ; }
135 VPUBLIC Vparam_ResData* Vparam_ResData_ctor(Vmem *mem) {
137 Vparam_ResData *thee = VNULL;
139 /* Set up the structure */
140 thee = (Vparam_ResData*)Vmem_malloc(mem, 1, sizeof(Vparam_ResData) );
141 VASSERT(thee != VNULL);
142 VASSERT(Vparam_ResData_ctor2(thee, mem));
147 VPUBLIC int Vparam_ResData_ctor2(Vparam_ResData *thee, Vmem *mem) {
150 Vnm_print(2, "Vparam_ResData_ctor2: Got VNULL thee!\n");
155 thee->atomData = VNULL;
160 VPUBLIC void Vparam_ResData_dtor(Vparam_ResData **thee) {
162 if ((*thee) != VNULL) {
163 Vparam_ResData_dtor2(*thee);
164 Vmem_free((*thee)->vmem, 1, sizeof(Vparam_ResData), (void **)thee);
170 VPUBLIC void Vparam_ResData_dtor2(Vparam_ResData *thee) {
172 if (thee == VNULL) return;
173 if (thee->nAtomData > 0) {
174 Vmem_free(thee->vmem, thee->nAtomData, sizeof(Vparam_AtomData),
175 (void **)&(thee->atomData));
178 thee->atomData = VNULL;
181 VPUBLIC Vparam* Vparam_ctor() {
183 Vparam *thee = VNULL;
185 /* Set up the structure */
186 thee = (Vparam*)Vmem_malloc(VNULL, 1, sizeof(Vparam) );
187 VASSERT(thee != VNULL);
188 VASSERT(Vparam_ctor2(thee));
193 VPUBLIC int Vparam_ctor2(Vparam *thee) {
196 Vnm_print(2, "Vparam_ctor2: got VNULL thee!\n");
201 thee->vmem = Vmem_ctor("APBS:VPARAM");
202 if (thee->vmem == VNULL) {
203 Vnm_print(2, "Vparam_ctor2: failed to init Vmem!\n");
208 thee->resData = VNULL;
213 VPUBLIC void Vparam_dtor(Vparam **thee) {
215 if ((*thee) != VNULL) {
217 Vmem_free(VNULL, 1, sizeof(Vparam), (void **)thee);
223 VPUBLIC void Vparam_dtor2(Vparam *thee) {
227 if (thee == VNULL) return;
229 /* Destroy the residue data */
230 for (i=0; i<thee->nResData; i++) Vparam_ResData_dtor2(&(thee->resData[i]));
231 if (thee->nResData > 0) Vmem_free(thee->vmem, thee->nResData,
232 sizeof(Vparam_ResData), (void **)&(thee->resData));
234 thee->resData = VNULL;
236 if (thee->vmem != VNULL) Vmem_dtor(&(thee->vmem));
241 VPUBLIC Vparam_ResData* Vparam_getResData(Vparam *thee,
242 char resName[VMAX_ARGLEN]) {
245 Vparam_ResData *res = VNULL;
247 VASSERT(thee != VNULL);
249 if ((thee->nResData == 0) || (thee->resData == VNULL)) {
254 /* Look for the matching residue */
255 for (i=0; i<thee->nResData; i++) {
256 res = &(thee->resData[i]);
257 if (Vstring_strcasecmp(resName, res->name) == 0) return res;
261 /* Didn't find a matching residue */
263 Vnm_print(2, "Vparam_getResData: unable to find res=%s\n", resName);
267 VPUBLIC Vparam_AtomData* Vparam_getAtomData(Vparam *thee,
268 char resName[VMAX_ARGLEN], char atomName[VMAX_ARGLEN]) {
271 Vparam_ResData *res = VNULL;
272 Vparam_AtomData *atom = VNULL;
274 VASSERT(thee != VNULL);
276 if ((thee->nResData == 0) || (thee->resData == VNULL)) {
281 /* Look for the matching residue */
282 res = Vparam_getResData(thee, resName);
285 Vnm_print(2, "Vparam_getAtomData: Unable to find residue %s!\n", resName);
288 for (i=0; i<res->nAtomData; i++) {
289 atom = &(res->atomData[i]);
291 Vnm_print(2, "Vparam_getAtomData: got NULL atom!\n");
294 if (Vstring_strcasecmp(atomName, atom->atomName) == 0) {
299 /* Didn't find a matching atom/residue */
301 Vnm_print(2, "Vparam_getAtomData: unable to find atom '%s', res '%s'\n",
306 VPUBLIC int Vparam_readXMLFile(Vparam *thee, const char *iodev,
307 const char *iofmt, const char *thost, const char *fname) {
309 int i, ires, natoms, nalloc, ralloc;
310 Vparam_AtomData *atoms = VNULL;
311 Vparam_AtomData *tatoms = VNULL;
312 Vparam_AtomData *atom = VNULL;
313 Vparam_ResData *res = VNULL;
314 Vparam_ResData *residues = VNULL;
315 Vparam_ResData *tresidues = VNULL;
317 char currResName[VMAX_ARGLEN];
318 char tok[VMAX_ARGLEN];
319 char endtag[VMAX_ARGLEN];
321 VASSERT(thee != VNULL);
323 /* Setup communication */
324 sock = Vio_ctor(iodev,iofmt,thost,fname,"r");
326 Vnm_print(2, "Vparam_readXMLFile: Problem opening virtual socket %s\n",
330 if (Vio_accept(sock, 0) < 0) {
331 Vnm_print(2, "Vparam_readXMLFile: Problem accepting virtual socket %s\n",
335 Vio_setWhiteChars(sock, MCxmlwhiteChars);
336 Vio_setCommChars(sock, MCcommChars);
338 /* Clear existing parameters */
339 if (thee->nResData > 0) {
340 Vnm_print(2, "WARNING -- CLEARING PARAMETER DATABASE!\n");
341 for (i=0; i<thee->nResData; i++) {
342 Vparam_ResData_dtor2(&(thee->resData[i]));
344 Vmem_free(thee->vmem, thee->nResData,
345 sizeof(Vparam_ResData), (void **)&(thee->resData));
350 /* Set up temporary residue list */
353 residues = (Vparam_ResData*)Vmem_malloc(thee->vmem, ralloc, sizeof(Vparam_ResData));
355 /* Read until we run out of entries, allocating space as needed */
358 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
360 /* The first token should be the start tag */
362 if (Vstring_strcasecmp(endtag, "/") == 0) strcat(endtag, tok);
364 if (Vstring_strcasecmp(tok, "residue") == 0) {
365 if (thee->nResData >= ralloc) {
366 tresidues = (Vparam_ResData*)Vmem_malloc(thee->vmem, 2*ralloc, sizeof(Vparam_ResData));
367 VASSERT(tresidues != VNULL);
368 for (i=0; i<thee->nResData; i++) {
369 Vparam_ResData_copyTo(&(residues[i]), &(tresidues[i]));
371 Vmem_free(thee->vmem, ralloc, sizeof(Vparam_ResData),
372 (void **)&(residues));
373 residues = tresidues;
378 /* Initial space for this residue's atoms */
381 atoms = (Vparam_AtomData*)Vmem_malloc(thee->vmem, nalloc, sizeof(Vparam_AtomData));
383 } else if (Vstring_strcasecmp(tok, "name") == 0) {
384 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1); /* value */
385 strcpy(currResName, tok);
386 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1); /* </name> */
387 } else if (Vstring_strcasecmp(tok, "atom") == 0) {
388 if (natoms >= nalloc) {
389 tatoms = (Vparam_AtomData*)Vmem_malloc(thee->vmem, 2*nalloc, sizeof(Vparam_AtomData));
390 VASSERT(tatoms != VNULL);
391 for (i=0; i<natoms; i++) {
392 Vparam_AtomData_copyTo(&(atoms[i]), &(tatoms[i]));
394 Vmem_free(thee->vmem, nalloc, sizeof(Vparam_AtomData),
400 atom = &(atoms[natoms]);
401 if (!readXMLFileAtom(sock, atom)) break;
404 } else if (Vstring_strcasecmp(tok, "/residue") == 0) {
406 res = &(residues[thee->nResData]);
407 Vparam_ResData_ctor2(res, thee->vmem);
408 res->atomData = (Vparam_AtomData*)Vmem_malloc(thee->vmem, natoms,
409 sizeof(Vparam_AtomData));
410 res->nAtomData = natoms;
411 strcpy(res->name, currResName);
412 for (i=0; i<natoms; i++) {
413 strcpy(atoms[i].resName, currResName);
414 Vparam_AtomData_copyTo(&(atoms[i]), &(res->atomData[i]));
416 Vmem_free(thee->vmem, nalloc, sizeof(Vparam_AtomData), (void **)&(atoms));
419 } else if (Vstring_strcasecmp(tok, endtag) == 0) break;
422 /* Initialize and copy the residues into the Vparam object */
424 thee->resData = (Vparam_ResData*)Vmem_malloc(thee->vmem, thee->nResData,
425 sizeof(Vparam_ResData));
426 for (ires=0; ires<thee->nResData; ires++) {
427 Vparam_ResData_copyTo(&(residues[ires]), &(thee->resData[ires]));
430 /* Destroy temporary atom space */
431 Vmem_free(thee->vmem, ralloc, sizeof(Vparam_ResData), (void **)&(residues));
433 /* Shut down communication */
434 Vio_acceptFree(sock);
440 Vnm_print(2, "Vparam_readXMLFile: Got unexpected EOF reading parameter file!\n");
445 VPUBLIC int Vparam_readFlatFile(Vparam *thee, const char *iodev,
446 const char *iofmt, const char *thost, const char *fname) {
448 int i, iatom, jatom, ires, natoms, nalloc;
449 Vparam_AtomData *atoms = VNULL;
450 Vparam_AtomData *tatoms = VNULL;
451 Vparam_AtomData *atom = VNULL;
452 Vparam_ResData *res = VNULL;
454 char currResName[VMAX_ARGLEN];
456 VASSERT(thee != VNULL);
458 /* Setup communication */
459 sock = Vio_ctor(iodev,iofmt,thost,fname,"r");
461 Vnm_print(2, "Vparam_readFlatFile: Problem opening virtual socket %s\n",
465 if (Vio_accept(sock, 0) < 0) {
466 Vnm_print(2, "Vparam_readFlatFile: Problem accepting virtual socket %s\n",
470 Vio_setWhiteChars(sock, MCwhiteChars);
471 Vio_setCommChars(sock, MCcommChars);
473 /* Clear existing parameters */
474 if (thee->nResData > 0) {
475 Vnm_print(2, "WARNING -- CLEARING PARAMETER DATABASE!\n");
476 for (i=0; i<thee->nResData; i++) {
477 Vparam_ResData_dtor2(&(thee->resData[i]));
479 Vmem_free(thee->vmem, thee->nResData,
480 sizeof(Vparam_ResData), (void **)&(thee->resData));
483 /* Initial space for atoms */
486 atoms = (Vparam_AtomData*)Vmem_malloc(thee->vmem, nalloc, sizeof(Vparam_AtomData));
488 /* Read until we run out of entries, allocating space as needed */
490 if (natoms >= nalloc) {
491 tatoms = (Vparam_AtomData*)Vmem_malloc(thee->vmem, 2*nalloc, sizeof(Vparam_AtomData));
492 VASSERT(tatoms != VNULL);
493 for (i=0; i<natoms; i++) {
494 Vparam_AtomData_copyTo(&(atoms[i]), &(tatoms[i]));
496 Vmem_free(thee->vmem, nalloc, sizeof(Vparam_AtomData),
502 atom = &(atoms[natoms]);
503 if (!readFlatFileLine(sock, atom)) break;
506 if (natoms == 0) return 0;
508 /* Count the number of residues */
510 strcpy(currResName, atoms[0].resName);
511 for (i=1; i<natoms; i++) {
512 if (Vstring_strcasecmp(atoms[i].resName, currResName) != 0) {
513 strcpy(currResName, atoms[i].resName);
518 /* Create the residues */
519 thee->resData = (Vparam_ResData*)Vmem_malloc(thee->vmem, thee->nResData,
520 sizeof(Vparam_ResData));
521 VASSERT(thee->resData != VNULL);
522 for (i=0; i<(thee->nResData); i++) {
523 res = &(thee->resData[i]);
524 Vparam_ResData_ctor2(res, thee->vmem);
527 /* Count the number of atoms per residue */
529 res = &(thee->resData[ires]);
531 strcpy(res->name, atoms[0].resName);
532 for (i=1; i<natoms; i++) {
533 if (Vstring_strcasecmp(atoms[i].resName, res->name) != 0) {
535 res = &(thee->resData[ires]);
537 strcpy(res->name, atoms[i].resName);
538 } else (res->nAtomData)++;
541 /* Allocate per-residue space for atoms */
542 for (ires=0; ires<thee->nResData; ires++) {
543 res = &(thee->resData[ires]);
544 res->atomData = (Vparam_AtomData*)Vmem_malloc(thee->vmem, res->nAtomData,
545 sizeof(Vparam_AtomData));
548 /* Copy atoms into residues */
550 Vparam_AtomData_copyTo(&(atoms[0]), &(res->atomData[iatom]));
551 for (ires=0; ires<thee->nResData; ires++) {
552 res = &(thee->resData[ires]);
553 for (jatom=0; jatom<res->nAtomData; jatom++) {
554 Vparam_AtomData_copyTo(&(atoms[iatom]), &(res->atomData[jatom]));
560 /* Shut down communication */
561 Vio_acceptFree(sock);
564 /* Destroy temporary atom space */
565 Vmem_free(thee->vmem, nalloc, sizeof(Vparam_AtomData), (void **)&(atoms));
571 VEXTERNC void Vparam_AtomData_copyTo(Vparam_AtomData *thee,
572 Vparam_AtomData *dest) {
574 VASSERT(thee != VNULL);
575 VASSERT(dest != VNULL);
577 strcpy(dest->atomName, thee->atomName);
578 strcpy(dest->resName, thee->resName);
579 dest->charge = thee->charge;
580 dest->radius = thee->radius;
581 dest->epsilon = thee->epsilon;
585 VEXTERNC void Vparam_ResData_copyTo(Vparam_ResData *thee,
586 Vparam_ResData *dest) {
590 VASSERT(thee != VNULL);
591 VASSERT(dest != VNULL);
593 strcpy(dest->name, thee->name);
594 dest->vmem = thee->vmem;
595 dest->nAtomData = thee->nAtomData;
597 dest->atomData = (Vparam_AtomData*)Vmem_malloc(thee->vmem, dest->nAtomData,
598 sizeof(Vparam_AtomData));
600 for (i=0; i<dest->nAtomData; i++) {
601 Vparam_AtomData_copyTo(&(thee->atomData[i]), &(dest->atomData[i]));
603 Vmem_free(thee->vmem, thee->nAtomData, sizeof(Vparam_AtomData),
604 (void **)&(thee->atomData));
607 VEXTERNC void Vparam_AtomData_copyFrom(Vparam_AtomData *thee,
608 Vparam_AtomData *src) { Vparam_AtomData_copyTo(src, thee); }
610 VPRIVATE int readXMLFileAtom(Vio *sock, Vparam_AtomData *atom) {
613 char tok[VMAX_BUFSIZE];
614 int chgflag, radflag, nameflag;
616 VASSERT(atom != VNULL);
618 if (Vio_scanf(sock, "%s", tok) != 1) return 0;
626 if (Vstring_strcasecmp(tok, "name") == 0) {
627 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
628 if (strlen(tok) > VMAX_ARGLEN) {
629 Vnm_print(2, "Vparam_readXMLFileAtom: string (%s) too long \
630 (%d)!\n", tok, strlen(tok));
634 strcpy(atom->atomName, tok);
635 } else if (Vstring_strcasecmp(tok, "charge") == 0) {
636 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
637 if (sscanf(tok, "%lf", &dtmp) != 1) {
638 Vnm_print(2, "Vparam_readXMLFileAtom: Unexpected token (%s) while \
639 parsing charge!\n", tok);
644 } else if (Vstring_strcasecmp(tok, "radius") == 0) {
645 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
646 if (sscanf(tok, "%lf", &dtmp) != 1) {
647 Vnm_print(2, "Vparam_readXMLFileAtom: Unexpected token (%s) while \
648 parsing radius!\n", tok);
653 } else if (Vstring_strcasecmp(tok, "epsilon") == 0) {
654 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
655 if (sscanf(tok, "%lf", &dtmp) != 1) {
656 Vnm_print(2, "Vparam_readXMLFileAtom: Unexpected token (%s) while \
657 parsing epsilon!\n", tok);
660 atom->epsilon = dtmp;
661 } else if ((Vstring_strcasecmp(tok, "/atom") == 0) ||
662 (Vstring_strcasecmp(tok, "atom") == 0)){
663 if (chgflag && radflag && nameflag) return 1;
665 Vnm_print(2, "Vparam_readXMLFileAtom: Reached end of atom without \
666 setting the charge!\n");
668 } else if (!radflag) {
669 Vnm_print(2, "Vparam_readXMLFileAtom: Reached end of atom without \
670 setting the radius!\n");
672 } else if (!nameflag) {
673 Vnm_print(2, "Vparam_readXMLFileAtom: Reached end of atom without \
674 setting the name!\n");
678 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
681 /* If we get here something wrong has happened */
686 Vnm_print(2, "Vparam_readXMLFileAtom: Got unexpected EOF reading parameter file!\n");
691 VPRIVATE int readFlatFileLine(Vio *sock, Vparam_AtomData *atom) {
694 char tok[VMAX_BUFSIZE];
696 VASSERT(atom != VNULL);
698 if (Vio_scanf(sock, "%s", tok) != 1) return 0;
699 if (strlen(tok) > VMAX_ARGLEN) {
700 Vnm_print(2, "Vparam_readFlatFile: string (%s) too long (%d)!\n",
704 strcpy(atom->resName, tok);
705 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
706 if (strlen(tok) > VMAX_ARGLEN) {
707 Vnm_print(2, "Vparam_readFlatFile: string (%s) too long (%d)!\n",
711 strcpy(atom->atomName, tok);
712 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
713 if (sscanf(tok, "%lf", &dtmp) != 1) {
714 Vnm_print(2, "Vparam_readFlatFile: Unexpected token (%s) while \
715 parsing charge!\n", tok);
719 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
720 if (sscanf(tok, "%lf", &dtmp) != 1) {
721 Vnm_print(2, "Vparam_readFlatFile: Unexpected token (%s) while \
722 parsing radius!\n", tok);
726 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
727 if (sscanf(tok, "%lf", &dtmp) != 1) {
728 Vnm_print(2, "Vparam_readFlatFile: Unexpected token (%s) while \
729 parsing radius!\n", tok);
732 atom->epsilon = dtmp;
737 Vnm_print(2, "Vparam_readFlatFile: Got unexpected EOF reading parameter file!\n");
#define VEMBED(rctag)
Allows embedding of RCS ID tags in object files.
VPRIVATE char * MCcommChars
Comment characters for socket reads.
VPRIVATE char * MCwhiteChars
Whitespace characters for socket reads.
Contains declarations for class Vparam.