      SUBROUTINE MODIFY
C
C MODIFY DERIVATIVES FOR CONSTRAINTS
C
      DIMENSION DERIV(200),LDEGN(25000),ADERIV(352)
      INCLUDE 'RFINE.PRM'
      INCLUDE 'A.INC'
      INCLUDE 'D.INC'
      INCLUDE 'LS.INC'
      INCLUDE 'LSMAT.INC'
      INCLUDE 'CNSTRS.INC'
      EQUIVALENCE (ADERIV,DAB),(DERIV(1),ADERIV(3)),(LDEGN,A)
C
      INCLUDE 'SHIFT.INC'
      I5(K)=IAND(K,65535)
C
C CALCULATE PARTIAL DERIVATIVES OF F
C
      IPNT=0
      DO 340 J=1,NATOM
        IPNT=IPNT+1
C DERIVATIVES WITH RESPECT TO OCCUPANCY
        AA(IPNT)=ACALC*DADO(J)+BCALC*DBDO(J)
C DERIVATIVES WITH RESPECT TO POSITION
        DO 300 I=1,3
          IPNT=IPNT+1
          AA(IPNT)=ACALC*DADX(I,J)+BCALC*DBDX(I,J)
  300   CONTINUE
        IJ=1
        IF(ISOT(J).GT.0)IJ=6
C DERIVATIVES WITH RESPECT TO BIJ'S
        DO 310 I=1,IJ
          IPNT=IPNT+1
          AA(IPNT)=ACALC*DADB(I,J)+BCALC*DBDB(I,J)
  310   CONTINUE
        IF(ISOT(J).LE.1)GO TO 340
C DERIVATIVES WITH RESPECT TO CIJ'S
        DO 320 I=1,10
          IPNT=IPNT+1
          AA(IPNT)=ACALC*DADC(I,J)+BCALC*DBDC(I,J)
  320   CONTINUE
        IF(ISOT(J).EQ.2)GO TO 340
C DERIVATIVES WITH RESPECT TO DIJ'S
        DO 330 I=1,15
          IPNT=IPNT+1
          AA(IPNT)=ACALC*DADD(I,J)+BCALC*DBDD(I,J)
  330   CONTINUE
  340 CONTINUE
C
C LOOP THROUGH ALL CONSTRAINTS
C
      DO 350 II=1,MDEGN,2
C EXTRACT PARAMETER INFORMATION FROM PACKED CONSTRAINTS
        IJ=I2(LDEGN(II))
        IK=I5(LDEGN(II))
        DERIV(IJ)=DERIV(IJ)+AA(IK)*A(II+1)
  350 CONTINUE
      RETURN
      END 
