



      SUBROUTINE PLN001 (IAA,RMS,A,B,C,D,IERR)






















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      LOGICAL       USEIT(MAXTAT)
      REAL          A, B, C, D, RMS, LOCXYZ(3,MAXTAT)
      INTEGER       IAA, IAT, IERR, IATR, NUM







      CALL PLN100 (IAA,USEIT)
      IATR=0
      NUM=0
      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IATR=IATR+1
         IF (USEIT(IATR).AND.ISATOK(IAT)) THEN
            NUM=NUM+1
            LOCXYZ(1,NUM)=XCOORD(IAT)
            LOCXYZ(2,NUM)=YCOORD(IAT)
            LOCXYZ(3,NUM)=ZCOORD(IAT)
         END IF
 10   CONTINUE



      IF (NUM.LT.4) THEN
         IERR=1
         GOTO 998
      END IF
      IERR=0



      CALL PLN004 (LOCXYZ,NUM,A,B,C,D,RMS)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN001A (IAA,RMS,A,B,C,D,IERR)



















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'REFINC.INC'
      INTEGER       IAA, IAT, IERR, IATR, NUM
      REAL          A, B, C, D, RMS, LOCXYZ(3,MAXTAT)
      LOGICAL       USEIT(MAXTAT)







      CALL GVSBTF (USEIT,MAXTAT)



      IATR=0
      NUM=0
      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IATR=IATR+1
         IF (PLANAR(IATR,1,RESTYP(IAA)).AND.ISATOK(IAT).AND.
     +       (.NOT.PROTON(IAT))) THEN
            NUM=NUM+1
            LOCXYZ(1,NUM)=XCOORD(IAT)
            LOCXYZ(2,NUM)=YCOORD(IAT)
            LOCXYZ(3,NUM)=ZCOORD(IAT)
         END IF
 10   CONTINUE



      IF (NUM.LT.4) THEN
         IERR=1
         GOTO 998
      END IF
      IERR=0



      CALL PLN004 (LOCXYZ,NUM,A,B,C,D,RMS)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN001B (IAA,RMS,A,B,C,D,IERR)

















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'REFINC.INC'
      INTEGER       IAA, IAT, IERR, IATR, NUM, IBND, JAT
      REAL          A, B, C, D, RMS, LOCXYZ(3,MAXTAT)
      LOGICAL       USEIT(MAXTAT)







      IATR=0
      NUM=0
      RMS=0.0
      CALL GVSBTF (USEIT,MAXTAT)



      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IATR=IATR+1
         IF (PLANAR(IATR,1,RESTYP(IAA)).AND.ISATOK(IAT).AND.
     +       (.NOT.PROTON(IAT))) THEN
            NUM=NUM+1
            LOCXYZ(1,NUM)=XCOORD(IAT)
            LOCXYZ(2,NUM)=YCOORD(IAT)
            LOCXYZ(3,NUM)=ZCOORD(IAT)
            USEIT(PINIAA(IAT))=.TRUE.
         END IF
   10 CONTINUE



      IF (NUM.LT.4) THEN
         IERR=1
         GOTO 998
      END IF
      IERR=0



      CALL PLN004 (LOCXYZ,NUM,A,B,C,D,RMS)
      PRPVAL(IAA)=MAX(0.0001,RMS)
      IATR=0
      DO 30 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IATR=IATR+1
         IF (PLANAR(IATR,1,RESTYP(IAA)).AND.ISATOK(IAT)) THEN
            CALL PLN007 (A,B,C,D,IAT)
         END IF
         DO 20 IBND=1,2
            JAT=BOUND_TO(IBND,IAT)
            IF (JAT.NE.0) THEN
               IF (PROTON(JAT)) THEN
                  CALL PLN007 (A,B,C,D,JAT)
               END IF
            END IF
   20    CONTINUE
   30 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN002



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INTEGER       IAA, IERR
      REAL          RMS, A, B, C, D







      DO 10 IAA=1,NUMAAF
         CALL PLN001 (IAA,RMS,A,B,C,D,IERR)
         IF (IERR.EQ.0) THEN
            PRPVAL(IAA)=RMS
         ELSE
            PRPVAL(IAA)=0.0
         END IF
 10   CONTINUE





      RETURN
      END
      SUBROUTINE PLN002A



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INTEGER       IAA, IERR
      REAL          RMS, A, B, C, D







      DO 10 IAA=1,NUMAAF
         CALL PLN001A (IAA,RMS,A,B,C,D,IERR)
         IF (IERR.EQ.0) THEN
            PRPVAL(IAA)=RMS
         ELSE
            PRPVAL(IAA)=0.0
         END IF
 10   CONTINUE





      RETURN
      END
      SUBROUTINE PLN003



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INCLUDE       'DATBAS.INC'
      INTEGER       ISEQ, IAA, INA, IAT
      REAL          SUMBFT

      RETURN
      END
      SUBROUTINE PLNTST

















      IMPLICIT      NONE
      REAL          DVA(3,4), A, B, C, D, RMS
      INTEGER       NUM







      NUM=4
      DVA(1,1)=0.000
      DVA(2,1)=0.000
      DVA(3,1)=-0.691
      DVA(1,2)=0.000
      DVA(2,2)=0.000
      DVA(3,2)=0.691
      DVA(1,3)=0.865
      DVA(2,3)=0.865
      DVA(3,3)=1.345
      DVA(1,4)=-0.865
      DVA(2,4)=-0.865
      DVA(3,4)=1.345

      CALL GVSBOX ('?M3398')
      CALL PLN004 (DVA,NUM,A,B,C,D,RMS)



      DVA(1,1)=0.001
      DVA(2,1)=-0.001
      DVA(1,2)=0.0015
      DVA(2,2)=-0.002
      CALL GVSBOX ('?M3399')
      CALL PLN004 (DVA,NUM,A,B,C,D,RMS)





      RETURN
      END   
      SUBROUTINE PLN004 (XYZ,NUM,A,B,C,D,RMS)



















      IMPLICIT      NONE
      INTEGER       NUM, I, ICNT
      REAL          XYZ(3,NUM), A, B, C, D, RMS, CENTROID(3), RMAT(3,3),
     +              EVEC(3,3), V(3), DIST, GVFRAN







      IF (NUM.LT.4) THEN
         CALL GVSTTE ('?M2133')
         A=1
         B=0
         C=0
         D=0
         RMS=0
         GOTO 998
      END IF



      ICNT=0



      CALL GVSRT0 (CENTROID,3)
      DO 10 I=1,NUM
         CENTROID(1)=CENTROID(1)+XYZ(1,I)
         CENTROID(2)=CENTROID(2)+XYZ(2,I)
         CENTROID(3)=CENTROID(3)+XYZ(3,I)
 10   CONTINUE

      CENTROID(1)=CENTROID(1)/FLOAT(NUM)
      CENTROID(2)=CENTROID(2)/FLOAT(NUM)
      CENTROID(3)=CENTROID(3)/FLOAT(NUM)



 15   CONTINUE
      CALL GVSRT0 (RMAT,9)
      DO 20 I=1,NUM
         IF (ICNT.EQ.0) THEN
            V(1)=XYZ(1,I)-CENTROID(1)
            V(2)=XYZ(2,I)-CENTROID(2)
            V(3)=XYZ(3,I)-CENTROID(3)
         ELSE
            V(1)=XYZ(1,I)-CENTROID(1)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
            V(2)=XYZ(2,I)-CENTROID(2)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
            V(3)=XYZ(3,I)-CENTROID(3)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
         END IF
         RMAT(1,1)=RMAT(1,1)+V(1)*V(1)
         RMAT(2,1)=RMAT(2,1)+V(2)*V(1)
         RMAT(3,1)=RMAT(3,1)+V(3)*V(1)
         RMAT(1,2)=RMAT(1,2)+V(1)*V(2)
         RMAT(2,2)=RMAT(2,2)+V(2)*V(2)
         RMAT(3,2)=RMAT(3,2)+V(3)*V(2)
         RMAT(1,3)=RMAT(1,3)+V(1)*V(3)
         RMAT(2,3)=RMAT(2,3)+V(2)*V(3)
         RMAT(3,3)=RMAT(3,3)+V(3)*V(3)
 20   CONTINUE



      CALL GVSEIG2 (3,RMAT,V,EVEC)



      IF (ABS(EVEC(1,1)).LT.0.0001.OR.
     +    ABS(EVEC(1,2)).LT.0.0001.OR.
     +    ABS(EVEC(1,3)).LT.0.0001.OR.
     +    ABS(EVEC(2,1)).LT.0.0001.OR.
     +    ABS(EVEC(2,2)).LT.0.0001.OR.
     +    ABS(EVEC(2,3)).LT.0.0001.OR.
     +    ABS(EVEC(3,1)).LT.0.0001.OR.
     +    ABS(EVEC(3,2)).LT.0.0001.OR.
     +    ABS(EVEC(3,3)).LT.0.0001) THEN
         IF (ICNT.LT.5) THEN
            ICNT=ICNT+1
            GOTO 15
         END IF
      END IF
      A=EVEC(1,3)
      B=EVEC(2,3)
      C=EVEC(3,3)
      D=A*CENTROID(1)+B*CENTROID(2)+C*CENTROID(3)



      RMS=0.0
      DO 30 I=1,NUM
         DIST=D-A*XYZ(1,I)-B*XYZ(2,I)-C*XYZ(3,I)
         RMS=RMS+DIST**2
 30   CONTINUE
      IF (NUM.GE.1) RMS=SQRT(RMS/NUM)
      CALL PLN004A (XYZ,NUM,A,B,C,D,RMS)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN004A (XYZ,NUM,A,B,C,D,RMSNOW)

















      IMPLICIT      NONE
      INTEGER       NUM, I, LOOP, WHO
      REAL          XYZ(3,NUM), A, B, C, D, GVFRAN, PLN004B, OLD(4), 
     +              NOW(4), STEP, RMSNOW, RMSTRY
      LOGICAL       FOUND







      OLD(1)=A
      OLD(2)=B
      OLD(3)=C
      OLD(4)=D
      STEP=2.0
      RMSTRY=PLN004B(XYZ,NUM,A,B,C,D)
      LOOP=0
      RMSNOW=RMSTRY
      DO 100 LOOP=1,250
         FOUND=.FALSE.
         DO 90 I=1,4
            CALL GVSCPR (NOW,OLD,4)
            WHO=MOD(I,4)+1
            A=NOW(1)+STEP*GVFRAN(-0.5,0.5)
            B=NOW(2)+STEP*GVFRAN(-0.5,0.5)
            C=NOW(3)+STEP*GVFRAN(-0.5,0.5)
            D=NOW(4)+STEP*GVFRAN(-0.5,0.5)
            CALL GVSNM3 (OLD)
            RMSTRY=PLN004B(XYZ,NUM,A,B,C,D)
            IF (RMSTRY.LT.RMSNOW) THEN
               FOUND=.TRUE.
               RMSNOW=RMSTRY
               CALL GVSCPR (OLD,NOW,4)
            END IF
 90      CONTINUE
         IF (.NOT.FOUND) STEP=STEP*(0.9)
         IF (ABS(STEP).LT.0.0001) STEP=1.0
 100  CONTINUE
      A=OLD(1)
      B=OLD(2)
      C=OLD(3)
      D=OLD(4)





      RETURN
      END   
      REAL FUNCTION PLN004B(XYZ,NUM,A,B,C,D)

















      IMPLICIT      NONE
      INTEGER       NUM, I
      REAL          XYZ(3,NUM), A, B, C, D, DIST, RMS







      RMS=0.0



      DO 10 I=1,NUM
         DIST=D-A*XYZ(1,I)-B*XYZ(2,I)-C*XYZ(3,I)
         RMS=RMS+DIST**2
 10   CONTINUE



      IF (NUM.GE.1) RMS=SQRT(RMS/NUM)
      PLN004B=RMS





      RETURN
      END   
      SUBROUTINE PLN004C (IAT1,IAT2,IAT3,IAT4,A,B,C,D,RMS)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       I, ICNT, IAT1, IAT2, IAT3, IAT4
      REAL          XYZL(3,4), A, B, C, D, RMS, CENTROID(3), RMAT(3,3),
     +              EVEC(3,3), V(3), DIST, GVFRAN







      ICNT=0
      XYZL(1,1)=XCOORD(IAT1)
      XYZL(2,1)=YCOORD(IAT1)
      XYZL(3,1)=ZCOORD(IAT1)
      XYZL(1,2)=XCOORD(IAT2)
      XYZL(2,2)=YCOORD(IAT2)
      XYZL(3,2)=ZCOORD(IAT2)
      XYZL(1,3)=XCOORD(IAT3)
      XYZL(2,3)=YCOORD(IAT3)
      XYZL(3,3)=ZCOORD(IAT3)
      XYZL(1,4)=XCOORD(IAT4)
      XYZL(2,4)=YCOORD(IAT4)
      XYZL(3,4)=ZCOORD(IAT4)



      CALL GVSRT0 (CENTROID,3)
      DO 10 I=1,4
         CENTROID(1)=CENTROID(1)+XYZL(1,I)
         CENTROID(2)=CENTROID(2)+XYZL(2,I)
         CENTROID(3)=CENTROID(3)+XYZL(3,I)
 10   CONTINUE

      CENTROID(1)=CENTROID(1)/4.0
      CENTROID(2)=CENTROID(2)/4.0
      CENTROID(3)=CENTROID(3)/4.0



 15   CONTINUE
      CALL GVSRT0 (RMAT,9)
      DO 20 I=1,4
         IF (ICNT.EQ.0) THEN
            V(1)=XYZL(1,I)-CENTROID(1)
            V(2)=XYZL(2,I)-CENTROID(2)
            V(3)=XYZL(3,I)-CENTROID(3)
         ELSE
            V(1)=XYZL(1,I)-CENTROID(1)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
            V(2)=XYZL(2,I)-CENTROID(2)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
            V(3)=XYZL(3,I)-CENTROID(3)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
         END IF
         RMAT(1,1)=RMAT(1,1)+V(1)*V(1)
         RMAT(2,1)=RMAT(2,1)+V(2)*V(1)
         RMAT(3,1)=RMAT(3,1)+V(3)*V(1)
         RMAT(1,2)=RMAT(1,2)+V(1)*V(2)
         RMAT(2,2)=RMAT(2,2)+V(2)*V(2)
         RMAT(3,2)=RMAT(3,2)+V(3)*V(2)
         RMAT(1,3)=RMAT(1,3)+V(1)*V(3)
         RMAT(2,3)=RMAT(2,3)+V(2)*V(3)
         RMAT(3,3)=RMAT(3,3)+V(3)*V(3)
 20   CONTINUE



      CALL GVSEIG2 (3,RMAT,V,EVEC)



      IF (ABS(EVEC(1,1)).LT.0.0001.OR.
     +    ABS(EVEC(1,2)).LT.0.0001.OR.
     +    ABS(EVEC(1,3)).LT.0.0001.OR.
     +    ABS(EVEC(2,1)).LT.0.0001.OR.
     +    ABS(EVEC(2,2)).LT.0.0001.OR.
     +    ABS(EVEC(2,3)).LT.0.0001.OR.
     +    ABS(EVEC(3,1)).LT.0.0001.OR.
     +    ABS(EVEC(3,2)).LT.0.0001.OR.
     +    ABS(EVEC(3,3)).LT.0.0001) THEN
         IF (ICNT.LT.5) THEN
            ICNT=ICNT+1
            GOTO 15
         END IF
      END IF
      A=EVEC(1,3)
      B=EVEC(2,3)
      C=EVEC(3,3)
      D=A*CENTROID(1)+B*CENTROID(2)+C*CENTROID(3)



      RMS=0.0
      DO 30 I=1,4
         DIST=D-A*XYZL(1,I)-B*XYZL(2,I)-C*XYZL(3,I)
         RMS=RMS+DIST**2
 30   CONTINUE
      RMS=SQRT(RMS/4.0)
      CALL PLN004A (XYZL,4,A,B,C,D,RMS)





      RETURN
      END
      SUBROUTINE PLN004D (IAT1,IAT2,IAT3,IAT4,IAT5,A,B,C,D,RMS)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       I, ICNT, IAT1, IAT2, IAT3, IAT4, IAT5
      REAL          XYZL(3,5), A, B, C, D, RMS, CENTROID(3), RMAT(3,3),
     +              EVEC(3,3), V(3), DIST, GVFRAN







      ICNT=0
      XYZL(1,1)=XCOORD(IAT1)
      XYZL(2,1)=YCOORD(IAT1)
      XYZL(3,1)=ZCOORD(IAT1)
      XYZL(1,2)=XCOORD(IAT2)
      XYZL(2,2)=YCOORD(IAT2)
      XYZL(3,2)=ZCOORD(IAT2)
      XYZL(1,3)=XCOORD(IAT3)
      XYZL(2,3)=YCOORD(IAT3)
      XYZL(3,3)=ZCOORD(IAT3)
      XYZL(1,4)=XCOORD(IAT4)
      XYZL(2,4)=YCOORD(IAT4)
      XYZL(3,4)=ZCOORD(IAT4)
      XYZL(1,5)=XCOORD(IAT5)
      XYZL(2,5)=YCOORD(IAT5)
      XYZL(3,5)=ZCOORD(IAT5)



      CALL GVSRT0 (CENTROID,3)
      DO 10 I=1,5
         CENTROID(1)=CENTROID(1)+XYZL(1,I)
         CENTROID(2)=CENTROID(2)+XYZL(2,I)
         CENTROID(3)=CENTROID(3)+XYZL(3,I)
 10   CONTINUE

      CENTROID(1)=CENTROID(1)/5.0
      CENTROID(2)=CENTROID(2)/5.0
      CENTROID(3)=CENTROID(3)/5.0



 15   CONTINUE
      CALL GVSRT0 (RMAT,9)
      DO 20 I=1,5
         IF (ICNT.EQ.0) THEN
            V(1)=XYZL(1,I)-CENTROID(1)
            V(2)=XYZL(2,I)-CENTROID(2)
            V(3)=XYZL(3,I)-CENTROID(3)
         ELSE
            V(1)=XYZL(1,I)-CENTROID(1)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
            V(2)=XYZL(2,I)-CENTROID(2)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
            V(3)=XYZL(3,I)-CENTROID(3)+FLOAT(ICNT)*GVFRAN(-0.002,0.002)
         END IF
         RMAT(1,1)=RMAT(1,1)+V(1)*V(1)
         RMAT(2,1)=RMAT(2,1)+V(2)*V(1)
         RMAT(3,1)=RMAT(3,1)+V(3)*V(1)
         RMAT(1,2)=RMAT(1,2)+V(1)*V(2)
         RMAT(2,2)=RMAT(2,2)+V(2)*V(2)
         RMAT(3,2)=RMAT(3,2)+V(3)*V(2)
         RMAT(1,3)=RMAT(1,3)+V(1)*V(3)
         RMAT(2,3)=RMAT(2,3)+V(2)*V(3)
         RMAT(3,3)=RMAT(3,3)+V(3)*V(3)
 20   CONTINUE



      CALL GVSEIG2 (3,RMAT,V,EVEC)



      IF (ABS(EVEC(1,1)).LT.0.0001.OR.
     +    ABS(EVEC(1,2)).LT.0.0001.OR.
     +    ABS(EVEC(1,3)).LT.0.0001.OR.
     +    ABS(EVEC(2,1)).LT.0.0001.OR.
     +    ABS(EVEC(2,2)).LT.0.0001.OR.
     +    ABS(EVEC(2,3)).LT.0.0001.OR.
     +    ABS(EVEC(3,1)).LT.0.0001.OR.
     +    ABS(EVEC(3,2)).LT.0.0001.OR.
     +    ABS(EVEC(3,3)).LT.0.0001) THEN
         IF (ICNT.LT.5) THEN
            ICNT=ICNT+1
            GOTO 15
         END IF
      END IF
      A=EVEC(1,3)
      B=EVEC(2,3)
      C=EVEC(3,3)
      D=A*CENTROID(1)+B*CENTROID(2)+C*CENTROID(3)



      RMS=0.0
      DO 30 I=1,5
         DIST=D-A*XYZL(1,I)-B*XYZL(2,I)-C*XYZL(3,I)
         RMS=RMS+DIST**2
 30   CONTINUE
      RMS=SQRT(RMS/5.0)
      CALL PLN004A (XYZL,5,A,B,C,D,RMS)





      RETURN
      END
      SUBROUTINE PLN005



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, ITYP, MAXIAA, NUM,GVFLEN
      REAL          SIGM(20), MAXVAL, SUM2
      LOGICAL       HASPROTEIN
      COMMON /PLN/  SIGM











      DATA          SIGM /0.0000,0.0000,0.0063,0.0063,0.0089,
     +                    0.0000,0.0046,0.0000,0.0000,0.0000,
     +                    0.0000,0.0059,0.0000,0.0059,0.0367,
     +                    0.0000,0.0000,0.0000,0.0135,0.0082/







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00014')
         GOTO 998
      END IF



      CALL PLN002














































      CALL CDB013 ('SSPLANOK','SSPLANEU','SSPLAOK')

      DO 100 IAA=1,NUMAAT
         ITYP=RESTYP(IAA)
         IF (ITYP.GE.1.AND.ITYP.LE.20) THEN
            IF (SIGM(ITYP).GT.0.0) THEN
               PRPVAL(IAA)=PRPVAL(IAA)/SIGM(ITYP)
               CALL PDBS50 (PNTAAC(IAA),0,0,0,ABS(PRPVAL(IAA)),4.0,10.0)
            ELSE
               PRPVAL(IAA)=-1000.0
            END IF
         ELSE
            PRPVAL(IAA)=-1000.0
         END IF
 100  CONTINUE



      SUM2=0.0
      NUM=0
      DO 200 IAA=1,NUMAAT
         IF (PRPVAL(IAA).GT.-900.) THEN
            NUM=NUM+1
            SUM2=SUM2+PRPVAL(IAA)**2
         END IF
  200 CONTINUE
      IF (NUM.GT.0) THEN
         GENRVL(32)=SQRT(SUM2/NUM)
      ELSE
         GENRVL(32)=-999.9
      END IF
      GENIVL(6)=NUM



      CALL GVSBTT (WRK1TF,MAXAA)
 10   CONTINUE
      MAXIAA=0
      MAXVAL=4.0
      DO 20 IAA=1,NUMAAF
         IF (WRK1TF(IAA).AND.PRPVAL(IAA).GT.MAXVAL) THEN
            MAXVAL=PRPVAL(IAA)
            MAXIAA=IAA
         END IF
 20   CONTINUE
      IF (MAXIAA.GT.0) THEN
         IAA=MAXIAA
         CALL PDBC92A (IAA,0)
         WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +    PRPVAL(IAA)
         CALL PDBC93 (LINE2)
         WRK1TF(IAA)=.FALSE.
         GOTO 10
      END IF

      CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('PLN005')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN005A




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, MAXIAA, GVFLEN
      REAL          MAXVAL
      LOGICAL       HASDNA, HASPROTON, WIFIRA







      IF (.NOT.HASDNA().AND.(.NOT.HASPROTON())) THEN
         CALL PDBMES ('R00014A')
         GOTO 998
      END IF



      CALL PLN002A



      CALL CDB013 ('UPLANOK','USSPLANEU','USSPLAOK')



      CALL GVSBTT (WRK1TF,MAXAA)
      IF (WIFPAR(84).EQ.0) THEN
         DO 5 IAA=1,NUMAAF



            IF (WIFIRA(IAA)) WRK1TF(IAA)=.FALSE.
    5    CONTINUE
      END IF



 10   CONTINUE
      MAXIAA=0
      MAXVAL=0.10
      DO 20 IAA=1,NUMAAF
         IF (WRK1TF(IAA).AND.PRPVAL(IAA).GT.MAXVAL) THEN
            MAXVAL=PRPVAL(IAA)
            MAXIAA=IAA
         END IF
 20   CONTINUE
      IF (MAXIAA.GT.0) THEN
         IAA=MAXIAA
         CALL PDBC92A (IAA,0)
         WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +    PRPVAL(IAA)
         CALL PDBC93 (LINE2)
         WRK1TF(IAA)=.FALSE.
         GOTO 10
      END IF

      CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('PLN005A')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN006 (IAA)





















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      REAL          A, B, C, D, RMS
      INTEGER       IAA, IAT, IERR
      REAL          SIGM(20)
      LOGICAL       CH4EQCH4
      COMMON /PLN/  SIGM







      DO 100 IAT=PNTAAS(IAA),PNTAAE(IAA)
         ATTVAL(IAT)=0.0
 100  CONTINUE
      IF (RESTYP(IAA).LT.1.OR.RESTYP(IAA).GT.20) GOTO 998



      CALL PLN001 (IAA,RMS,A,B,C,D,IERR)



      IF (IERR.EQ.0.AND.RMS.LT.4.0*SIGM(RESTYP(IAA))) THEN



         IF (CH4EQCH4(ONESA3(IAA),'PHE ')) THEN
            CALL PLN007 (A,B,C,D,PNTAAS(IAA)+4)
         ELSE IF (CH4EQCH4(ONESA3(IAA),'HIS ')) THEN
            CALL PLN007 (A,B,C,D,PNTAAS(IAA)+4)
         ELSE IF (CH4EQCH4(ONESA3(IAA),'TRP ')) THEN
            CALL PLN007 (A,B,C,D,PNTAAS(IAA)+4)
         ELSE IF (CH4EQCH4(ONESA3(IAA),'TYR ')) THEN
            CALL PLN007 (A,B,C,D,PNTAAS(IAA)+4)
            CALL PLN007 (A,B,C,D,PNTAAS(IAA)+11)
         END IF
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN006A (IAA)

















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, IERR
      REAL          SIGM(20), A, B, C, D, RMS
      LOGICAL       WIFIRA, WIFIRN
      COMMON /PLN/  SIGM







      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         ATTVAL(IAT)=-1.0
   10 CONTINUE



      IF (.NOT.(WIFIRA(IAA).OR.WIFIRN(IAA))) GOTO 998



      CALL PLN001B (IAA,RMS,A,B,C,D,IERR)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN007 (A,B,C,D,IAT)



















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC' 
      REAL          A, B, C, D
      INTEGER       IAT





      IF (ISATOK(IAT)) THEN
         ATTVAL(IAT)=ABS(A*XCOORD(IAT)+B*YCOORD(IAT)+C*ZCOORD(IAT)-D)
      ELSE
         ATTVAL(IAT)=0.0
      END IF





      RETURN
      END
      SUBROUTINE PLN008



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INCLUDE       'DATBAS.INC'
      INTEGER       ISEQ, IAA, IAT

      RETURN
      END
      SUBROUTINE PLN009



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INTEGER       IAA







      CALL GVSRT0 (ATTVAL,MAXAT)



      DO 10 IAA=1,NUMAAF
         CALL PLN006 (IAA)
 10   CONTINUE





      RETURN
      END
      SUBROUTINE PLN010



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INTEGER       IAA, IAT, IERR
      LOGICAL       GVFISF







      CALL GVSCLF (1)
      CALL GETFILE (1,'?FILNAM',' ',IERR)
      IF (IERR.NE.0) GOTO 998



   40 CONTINUE
         CALL GVSCTB (LINE2,80)



         CALL GETLINE (1,LINE2,IERR)
         IF (IERR.NE.0) GOTO 998
         IF (LINE2(1:1).NE.'/') GOTO 40
         CALL MOL712 (LINE2)



         IF (.NOT.GVFISF(LINE2)) THEN
            CALL GVST6C ('?SYM011',LINE2,.TRUE.)
            GOTO 40
         END IF



         FILNMS(62)=LINE2
         CALL TEXSTORE (LINE2)
         CALL MOL015 (LINE2)
         IF (NUMAAF.LT.1) then
            PRINT *, 'huh?'
            GOTO 40
         END IF
         CALL PLN009



         DO 90 IAA=1,NUMAAF
            DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (ATTVAL(IAT).GT.0.0) THEN
                  WRITE (77,*,ERR=999) ONESA3(IAA),IAT-PNTAAS(IAA)+1,
     +             ATTVAL(IAT)
               END IF
 80         CONTINUE
 90      CONTINUE
      GOTO 40



  999 CONTINUE
      CALL GVSEIW ('PLN010')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN011



















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC' 
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC' 
      INTEGER       IAA, IAT, MAXIAT, NUM, GVFLEN
      REAL          MAXVAL, SUM2
      LOGICAL       HASPROTEIN, CH4EQCH4







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00014')
         GOTO 998
      END IF



      CALL PLN009





























      CALL CDB013 ('SSPL2NOK','SSPL2NEU','SSPL2OK')

      DO 100 IAA=1,NUMAAF
         IF (CH4EQCH4(ONESA3(IAA),'PHE ')) THEN
            ATTVAL(PNTAAS(IAA)+4)=ATTVAL(PNTAAS(IAA)+4)/0.0643
         ELSE IF (CH4EQCH4(ONESA3(IAA),'HIS ')) THEN
            ATTVAL(PNTAAS(IAA)+4)=ATTVAL(PNTAAS(IAA)+4)/0.0504
         ELSE IF (CH4EQCH4(ONESA3(IAA),'TRP ')) THEN
            ATTVAL(PNTAAS(IAA)+4)=ATTVAL(PNTAAS(IAA)+4)/0.0743
         ELSE IF (CH4EQCH4(ONESA3(IAA),'TYR ')) THEN
            ATTVAL(PNTAAS(IAA)+4)=ATTVAL(PNTAAS(IAA)+4)/0.0610
            ATTVAL(PNTAAS(IAA)+11)=ATTVAL(PNTAAS(IAA)+11)/0.0403
         END IF
 100  CONTINUE
      DO 110 IAT=1,NUMATF
         IF (ATTVAL(IAT).EQ.0.0) ATTVAL(IAT)=-1000.0
 110  CONTINUE



      SUM2=0.0
      NUM=0
      DO 200 IAA=1,NUMAAT
         IF (PRPVAL(IAA).GT.-900.) THEN
            NUM=NUM+1
            SUM2=SUM2+PRPVAL(IAA)**2
         END IF
  200 CONTINUE
      IF (NUM.GT.0) THEN
         GENRVL(33)=SQRT(SUM2/NUM)
      ELSE
         GENRVL(33)=-999.
      END IF
      GENIVL(7)=NUM



      CALL GVSBTT (USEAT,MAXAT)
 10   CONTINUE
      MAXIAT=0
      MAXVAL=4.0
      DO 20 IAT=1,NUMATF
         IF (USEAT(IAT).AND.ATTVAL(IAT).GT.MAXVAL) THEN
            MAXVAL=ATTVAL(IAT)
            MAXIAT=IAT
         END IF
 20   CONTINUE
      IF (MAXIAT.GT.0) THEN
         IAT=MAXIAT
         CALL PDBS50 (IAT,0,0,0,ABS(ATTVAL(IAT)),4.0,12.0)
         CALL PDBC92A (0,IAT)
         CALL GVSCTB (LINE2,80)
         WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +    ATTVAL(IAT)
         CALL PDBC93 (LINE2)
         USEAT(IAT)=.FALSE.
         GOTO 10
      END IF
      CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('PLN011')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN012

















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, GVFLEN, ICNT, IBND, JAT
      REAL          RMSH(MAXAA)
      LOGICAL       HASPROTEIN, HASPROTON
      EQUIVALENCE   (RMSH(1),FUTURE(1))







      IF (WIFPAR(84).EQ.0) GOTO 998
      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00014')
         GOTO 998
      END IF
      IF (.NOT.HASPROTON()) THEN
         CALL PDBMES ('R00014A')
         GOTO 998
      END IF



      ICNT=0
      CALL GVSRT0 (ATTVAL,MAXAT)




      DO 30 IAA=1,NUMAAF
         CALL PLN006A (IAA)
         RMSH(IAA)=0.0



         DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (ISATOK(IAT).AND.PROTON(IAT).AND.ATTVAL(IAT).GE.0.0) THEN
               RMSH(IAA)=RMSH(IAA)+ATTVAL(IAT)**2
               ICNT=ICNT+1
            END IF



            DO 10 IBND=1,2
               JAT=BOUND_TO(IBND,IAT)
               IF (JAT.NE.0) THEN
                  IF (PROTON(JAT)) THEN
                     RMSH(IAA)=RMSH(IAA)+ATTVAL(IAT)**2
                     ICNT=ICNT+1
                  END IF
               END IF
   10       CONTINUE
   20    CONTINUE



         IF (PRPVAL(IAA).LT.0.0001) THEN
            CALL DIF008 ('?M3586',IAA)
         END IF
         IF (ICNT.GE.1.AND.PRPVAL(IAA).GE.0.0001) THEN
            RMSH(IAA)=SQRT(RMSH(IAA)/FLOAT(ICNT))
            PRPVAL(IAA)=RMSH(IAA)/PRPVAL(IAA)
         ELSE
            RMSH(IAA)=-1.0
            PRPVAL(IAA)=-1.0
         END IF
   30 CONTINUE




      CALL CDB013 ('SSPLHNOK',' ','SSPLHOK')



      DO 50 IAA=1,NUMAAF
         IF (PRPVAL(IAA).GT.1.5) THEN
            DO 40 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (PROTON(IAT).AND.ATTVAL(IAT).GT.0.05) THEN
                  CALL PDBC92A (0,IAT)
                  CALL GVSCTB (LINE2,80)
                  WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +             ATTVAL(IAT)
                  CALL PDBC93 (LINE2)
               END IF
 40         CONTINUE
         END IF
   50 CONTINUE
      CALL CDB012
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('PLN012')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PLN100 (IAA,USEIT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA
      LOGICAL       USEIT(MAXTAT), WIFIRR, CH4EQCH4







      CALL GVSBTF (USEIT,MAXTAT)



      IF (.NOT.WIFIRR(IAA)) GOTO 998



      IF (CH4EQCH4(ONESA3(IAA),'ASP ')) THEN
         CALL GVSBTT (USEIT(5),4)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'GLU ')) THEN
         CALL GVSBTT (USEIT(6),4)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'PHE ')) THEN
         CALL GVSBTT (USEIT(6),6)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'HIS ')) THEN
         CALL GVSBTT (USEIT(6),5)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'ASN ')) THEN
         CALL GVSBTT (USEIT(5),4)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'GLN ')) THEN
         CALL GVSBTT (USEIT(6),4)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'ARG ')) THEN
         CALL GVSBTT (USEIT(7),5)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'TRP ')) THEN
         CALL GVSBTT (USEIT(6),9)
      ELSE IF (CH4EQCH4(ONESA3(IAA),'TYR '))THEN
         CALL GVSBTT (USEIT(6),6)
      ELSE IF (ONESA3(IAA).EQ.'DADE') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),10)
      ELSE IF (ONESA3(IAA).EQ.'DTHY') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),9)
      ELSE IF (ONESA3(IAA).EQ.'DGUA') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),11)
      ELSE IF (ONESA3(IAA).EQ.'DCYT') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),8)
      ELSE IF (ONESA3(IAA).EQ.'OADE') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),10)
      ELSE IF (ONESA3(IAA).EQ.'OTHY') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),9)
      ELSE IF (ONESA3(IAA).EQ.'OGUA') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),11)
      ELSE IF (ONESA3(IAA).EQ.'OCYT') THEN
         USEIT(10)=.TRUE.
         CALL GVSBTT (USEIT(12),8)
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PLN101

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IERR
      REAL          RMS, A, B, C, D







      DO 100 IAA=1,NUMAAT
         CALL PLN001 (IAA,RMS,A,B,C,D,IERR)
         IF (IERR.NE.0) THEN
            CALL DIF008 ('?M3401',IAA)
            GOTO 100
         END IF
         PRPVAL(IAA)=100.0*RMS
         CALL SHOIAA (IAA)
         CALL PLN001A (IAA,RMS,A,B,C,D,IERR)
         PRPVAL(IAA)=100.0*RMS
         CALL SHOIAA (IAA)
  100 CONTINUE





      RETURN
      END   
