********>Bugfix.29:
Author: Ross Walker
Date: 01/10/2005
Programs: ambpdb
Description: ambpdb may give a segmentation fault on some machines when trying
to convert restrt files to pdb files. This was due to some array
out of bounds errors that were not tested for in the code. This
patch file will replace the static memory allocation in ambpdb
with dynamic memory allocation and at the same time fix the
segmentation fault bug. For this bugfix to work you must have
previously applied bugfix.11.
Fix: apply the following patch to amber8/src/etc/ambpdb.f
------------------------------------------------------------------------------
--- src/etc/ambpdb.f 2004-01-05 12:50:49.000000000 -0800
+++ src/etc/ambpdb.f 2004-12-16 10:19:18.000000000 -0800
@@ -2,28 +2,21 @@
c Simple filter program to convert AMBER coordinate files into PDB files
c (and to do other similar conversions).
c
- character*80 arg,prmtop,title
- character*8 hbenec
- character*6 arg1,arg2
- character*4 igraph,lbres
- character*1 ftype
- double precision c
- integer access, fhybrid, fhbdon, fhbh, fhbacc, ntf, itf, jtf
- double precision fhbene, hbene
+ implicit none
+ character(len=80) arg,prmtop,title
+ character(len=8) hbenec
+ character(len=6) arg1,arg2
+ character(len=4), dimension(:), allocatable :: igraph,lbres
+ character(len=1), dimension(:), allocatable :: ftype
+ integer access, ntf, ioffset, iarg, indx, iargc, natom, nres
+ integer nbond, ier, kcform, idbl, j, nhb
+ character(len=4) ititl(20)
+ double precision hbene
logical alttit,center,aatm,bres,ter,bin
- parameter( MAXATOM=150000 )
- parameter( MAXRES=50000 )
- parameter( MAXFHB=50000 )
-C
- DIMENSION C(3*MAXATOM),IGRAPH(3*MAXATOM),IPRES(MAXRES),
- . LBRES(MAXRES),lastat(MAXRES)
- DIMENSION ITITL(20),ib(MAXATOM),jb(MAXATOM),chg(MAXATOM)
- DIMENSION FTYPE(MAXATOM), FHYBRID(MAXATOM)
- DIMENSION FHBDON(MAXFHB), FHBH(MAXFHB), FHBACC(MAXFHB),
- . FHBENE(MAXFHB)
- DIMENSION itf(MAXATOM), jtf(MAXATOM)
- dimension c3(3,1)
- equivalence (c(1),c3(1,1))
+c
+ double precision, dimension(:), allocatable :: C,chg,fhbene
+ integer, dimension(:), allocatable :: IPRES,lastat,ib,jb,fhybrid,
+ . fhbdon,fhbh,fhbacc,itf,jtf
c
c ------ check argument options
c
@@ -87,6 +80,21 @@
C ----- OPEN THE PARM FILE AND LOAD THE NECESSARY STUFF -----
C
call amopen(10,prmtop,'O','F','R')
+ CALL GETNAM0(NATOM,NRES,NBOND,10)
+ REWIND(UNIT=10)
+c
+c ------ Allocate memory: ------
+c
+ allocate( c(3*natom), igraph(natom), ipres(nres), lbres(nres),
+ . lastat(nres), ib(nbond), jb(nbond), chg(natom),
+ . ftype(natom), fhybrid(natom), fhbdon(natom),fhbh(natom),
+ . fhbacc(natom), fhbene(natom), itf(natom), jtf(natom),
+ . stat = ier)
+ if (ier /= 0 ) then
+ write(0,*) 'memory allocation failure'
+ call mexit(6,1)
+ end if
+c
CALL GETNAM(NATOM,NRES,IGRAPH,IPRES,LBRES,ITITL,10,1,
1 C,C,C,ib,jb,nbond,chg,lastat,ter)
CLOSE(UNIT=10)
@@ -103,14 +111,14 @@
. ib, jb, nbond, ftype)
call gethybrid(NATOM, NRES, IGRAPH, IPRES, ib, jb,
. nbond, c, fhybrid)
- call findtf(MAXATOM, nbond, ib, jb, fhybrid, igraph,
+ call findtf(NATOM, nbond, ib, jb, fhybrid, igraph,
. ntf, itf, jtf)
- call corbondl(MAXATOM, NATOM, IGRAPH, NRES, IPRES, LBRES,
+ call corbondl(NATOM, NATOM, IGRAPH, NRES, IPRES, LBRES,
. nbond, ib, jb, c)
- call findhbond(MAXFHB, NATOM, NRES, IGRAPH, IPRES, ib, jb,
+ call findhbond(NATOM, NATOM, NRES, IGRAPH, IPRES, ib, jb,
. nbond, c, ftype, fhybrid,
. nhb, fhbdon, fhbh, fhbacc, fhbene)
- call addtether(MAXFHB, MAXATOM, MAXRES, NATOM, NRES,
+ call addtether(NATOM, NATOM, NRES, NATOM, NRES,
. IGRAPH, IPRES, LBRES, ib, jb, nbond, c,
. ftype, fhybrid,
. nhb, fhbdon, fhbh, fhbacc, fhbene)
@@ -152,14 +160,40 @@
C
C=====================================================================
C
+ SUBROUTINE GETNAM0(NATOM,NRES,MBONA,NF)
+c
+ CHARACTER*80 FMT,FMTIN,IFMT,AFMT,RFMT,TYPE
+ character(len=4) ITITL(20)
+ IFMT = '(12I6)'
+ AFMT = '(20A4)'
+ RFMT = '(5E16.8)'
+C
+C ----- READ THE MOLECULAR TOPOLOGY -----
+C
+ FMTIN = AFMT
+ TYPE = 'TITLE'
+ CALL NXTSEC(NF, 0, 0,FMTIN, TYPE, FMT, IOK)
+ READ(NF,FMT) (ITITL(I),I=1,20)
+c
+ FMTIN = IFMT
+ TYPE = 'POINTERS'
+ CALL NXTSEC(NF, 6, 0,FMTIN, TYPE, FMT, IOK)
+ READ(NF,FMT) NATOM,NTYPES,NBONH,MBONA,NTHETH,MTHETA,NPHIH,MPHIA,
+ 1 NHPARM,NPARM,NNB,NRES
+ !---- fix for allocating bond arrays ------
+ mbona = mbona+nbonh
+
+ RETURN
+ END
+C
+C=====================================================================
+C
SUBROUTINE GETNAM(NATOM,NRES,IGRAPH,IPRES,LBRES,ITITL,NF,KPF,
1 X,IX,IH,ib,jb,nbond,chg,lastat,ter)
- character*4 igraph,lbres
+ character(len=4) igraph,lbres,ititl
logical ter
- parameter( MAXATOM=150000 )
- parameter( MAXRES=50000 )
- DIMENSION IGRAPH(2),IPRES(2),LBRES(2),ITITL(20)
- DIMENSION X(2),IX(2),IH(2),ib(*),jb(*),chg(*),lastat(*)
+ DIMENSION IGRAPH(*),IPRES(*),LBRES(*),ITITL(20)
+ DIMENSION X(*),IX(*),IH(*),ib(*),jb(*),chg(*),lastat(*)
CHARACTER*80 FMT
CHARACTER*80 FMTIN,IFMT,AFMT,RFMT,TYPE
IFMT = '(12I6)'
@@ -181,12 +215,6 @@
1 NUMBND,NUMANG,NPTRA,NATYP,NPHB,IFPERT,NBPER,NGPER,
1 NDPER,MBPER,MGPER,MDPER,IFBOX,NMXRS,IFCAP
C
- if( NATOM.gt.MAXATOM .or. NRES.gt.MAXRES) then
- write(6,*) 'NATOM or NRES is too big:'
- write(6,*) ' NATOM = ',natom,'; max is ',MAXATOM
- write(6,*) ' NRES = ',nres, '; max is ',MAXRES
- stop
- end if
NTYPE = NTYPES*NTYPES
C
C ----- READ THE SYMBOLS AND THE CHARGES AND THE MASSES -----
@@ -349,8 +377,9 @@
character*3 resnam
character*1 type, ftype
character*40 title
+ character(len=4) ititl(20)
logical alttit,center,aatm,bres
- DIMENSION C(2),IGRAPH(2),IPRES(2),LBRES(2),ITITL(20),chg(*),
+ DIMENSION C(2),IGRAPH(2),IPRES(2),LBRES(2),chg(*),
. lastat(*)
DIMENSION ftype(*)
dimension elrad(15)
@@ -559,7 +588,8 @@
C
SUBROUTINE GETCOR(bin,NATOM,C,CD,KCF,IDBL,NF)
DOUBLE PRECISION C, CD
- DIMENSION C(2),CD(2),ITITL(20)
+ character(len=4) ititl(20)
+ DIMENSION C(2),CD(2)
integer fh
character*80 line
logical bin
------------------------------------------------------------------------------
Workarounds: Use carnal or ptraj for pdb files.