Adam's homology version of unres with new readpdb.F now in src_MD
authorFelipe Pineda <pideca@hotmail.com>
Fri, 17 Oct 2014 10:00:05 +0000 (12:00 +0200)
committerFelipe Pineda <pideca@hotmail.com>
Fri, 17 Oct 2014 10:00:05 +0000 (12:00 +0200)
22 files changed:
source/unres/src_MD/COMMON.CONTROL
source/unres/src_MD/COMMON.DERIV
source/unres/src_MD/COMMON.DFA [new file with mode: 0644]
source/unres/src_MD/COMMON.FFIELD
source/unres/src_MD/COMMON.MD
source/unres/src_MD/DIMENSIONS
source/unres/src_MD/DIMENSIONS.2100
source/unres/src_MD/DIMENSIONS.4100
source/unres/src_MD/MREMD.F
source/unres/src_MD/Makefile_MPICH_PGI [new file with mode: 0644]
source/unres/src_MD/Makefile_MPICH_ifort
source/unres/src_MD/cinfo.f
source/unres/src_MD/dfa.F [new file with mode: 0644]
source/unres/src_MD/energy_p_new_barrier.F
source/unres/src_MD/energy_split-sep.F
source/unres/src_MD/geomout.F
source/unres/src_MD/initialize_p.F
source/unres/src_MD/readpdb.F
source/unres/src_MD/readrtns.F
source/unres/src_MD/ssMD.F
source/unres/src_MD/timing.F
source/unres/src_MD/unres.F

index c12ef3a..9fce3c5 100644 (file)
@@ -1,5 +1,6 @@
       integer modecalc,iscode,indpdb,indback,indphi,iranconf,icheckgrad,
-     & inprint,i2ndstr,mucadyn,constr_dist
+     & inprint,i2ndstr,mucadyn,constr_dist,constr_homology
+      real*8 waga_dist, waga_angle
       logical minim,refstr,pdbref,outpdb,outmol2,overlapsc,energy_dec,
      &                 sideadd,lsecondary,read_cart,unres_pdb,
      &                 vdisulf,searchsc,lmuca,dccart,extconf,out1file,
@@ -8,6 +9,7 @@
      & icheckgrad,minim,i2ndstr,refstr,pdbref,outpdb,outmol2,iprint,
      & overlapsc,energy_dec,sideadd,lsecondary,read_cart,unres_pdb
      & ,vdisulf,searchsc,lmuca,dccart,mucadyn,extconf,out1file,
-     & constr_dist,gnorm_check,gradout,split_ene
+     & constr_dist,gnorm_check,gradout,split_ene,constr_homology,
+     & waga_dist, waga_angle
 C... minim = .true. means DO minimization.
 C... energy_dec = .true. means print energy decomposition matrix
index 6fdb1aa..67ebfdc 100644 (file)
@@ -22,7 +22,8 @@
      & g_corr5_loc(maxvar),g_corr6_loc(maxvar),gsccorc(3,maxres),
      & gsccorx(3,maxres),gsccor_loc(maxres),dtheta(3,2,maxres),
      & gscloc(3,maxres),gsclocx(3,maxres),
-     & dphi(3,3,maxres),dalpha(3,3,maxres),domega(3,3,maxres),nfl,icg
+     & dphi(3,3,maxres),dalpha(3,3,maxres),domega(3,3,maxres),nfl,icg,
+     & gdfad(3,maxres),gdfat(3,maxres),gdfan(3,maxres),gdfab(3,maxres)
       double precision derx,derx_turn
       common /deriv_loc/ derx(3,5,2),derx_turn(3,5,2)
       double precision dXX_C1tab(3,maxres),dYY_C1tab(3,maxres),
diff --git a/source/unres/src_MD/COMMON.DFA b/source/unres/src_MD/COMMON.DFA
new file mode 100644 (file)
index 0000000..c6add4f
--- /dev/null
@@ -0,0 +1,101 @@
+C =======
+C COMMON.DFA
+C =======
+C 2010/12/20 By Juyong Lee
+C
+c parameter
+C [ 8 * ( Nres - 8 ) ] distance restraints 
+C [ 2 * ( Nres - 8 ) ] angle restraints
+C [ Nres ]             neighbor restraints
+C Total : ~ 11 * Nres restraints
+C
+C
+      INTEGER IDFAMAX,IDFAMX2,IDFACMD,IDMAXMIN, MAXN
+      PARAMETER(IDFAMAX=4000,IDFAMX2=1000,IDFACMD=500,IDMAXMIN=500)
+      PARAMETER(MAXN=4)
+      real*8 wwdist,wwangle,wwnei
+      parameter(wwdist=1.0d0,wwangle=1.0d0,wwnei=1.0d0)
+
+C IDFAMAX  - maximum number of DFA restraint including distance, angle and
+C            number of neighbors ( Max of assign statement )
+C IDFAMX2  - maximum number of atoms which are targets of restraints
+C IDFACMD  - maximum number of 'DFA' command call
+C IDMAXMIN - Maximum number of minima of dist, angle and neighbor info. from fragments
+C MAXN     - Maximum Number of shell, currently 4
+C MAXRES   - Maximum number of CAs
+
+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCc
+C INTEGER 
+C DFANUM  - Number of ALL DFA restrants
+c IDFA[DIS, PHI, THE, NEI] - NUMBER of restraints
+c IDISNUM - number of minima for a distance restraint
+c IPHINUM - number of minima for a phi angle restraint
+c ITHENUM - number of minima for a theta angle restraint
+c INEINUM - number of minima for a number of neighbors restraint
+
+c IDISLIS - atom number of two atoms for distance restraint
+c IPHILIS - atom numbers of four atoms for angle restraint
+c ITHELIS - atom numbers of four atoms for angle restraint
+c INEILIS - atom number of center of neighbor calculation
+c JNEILIS - atom number of target of neighboring calculation
+c JNEINUM - number of target atoms of neighboring term
+C KSHELL  - SHELL number 
+
+C ishiftca - index shift for CA atoms in UNRES (1 if the 1st aa != GLY)
+C ilastca  - index of the last CA atom in UNRES (nres-1 if last aa != GLY)
+
+C     old only for CHARMM
+C STOAGDF - Store assign information ( How many assign within one command )
+C NMAP    - mapping between dfanum and ndis, nphi, nthe, nnei
+
+      INTEGER IDFADIS,IDFAPHI,IDFATHE,IDFANEI,
+     &               IDISLIS,IPHILIS,ITHELIS,INEILIS,
+     &        IDISNUM,IPHINUM,ITHENUM,INEINUM,
+     &        FNEI,DFACMD, DFANUM,
+     &        NCA,ICAIDX,
+     &        STOAGDF, NMAP, IDFACAT, KDISNUM, KSHELL
+     &        ishiftca,ilastca 
+      COMMON /IDFA/ DFACMD, DFANUM,
+     &              IDFADIS, IDFAPHI, IDFANEI, IDFATHE, 
+     &              IDISNUM(IDFAMAX), IPHINUM(IDFAMAX), 
+     &              ITHENUM(IDFAMAX), INEINUM(IDFAMAX),
+     &              FNEI(IDFAMAX,IDMAXMIN), IDISLIS(2,IDFAMAX),
+     &              IPHILIS(5,IDFAMAX), ITHELIS(5,IDFAMAX),
+     &              INEILIS(IDFAMAX),
+     &               KSHELL(IDFAMAX),
+     &              IDFACAT(IDFACMD),
+     &              KDISNUM(IDFAMAX),
+     &              NCA, ICAIDX(MAXRES)
+      COMMON /IDFA2/ ishiftca,ilastca
+
+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
+C
+C REAL VARIABLES
+C
+c SCC[DIST, PHI, THE] - weight of each calculations
+c FDIST  - distance minima
+C FPHI   - phi minima
+c FTHE   - theta minima
+C DFAEXP  : calculate expential function in advance
+C
+      REAL*8 SCCDIST, SCCPHI, SCCTHE, SCCNEI, FDIST, FPHI1, FPHI2,
+     &       FTHE1, FTHE2,
+     &       DIS_INC, PHI_INC, THE_INC, NEI_INC, BETA_INC,
+     &       WSHET, EDFABET, 
+     &       CK, SCK, S1, S2
+c    &       ,DFAEXP
+
+      COMMON /RDFA/ SCCDIST(IDFAMAX,IDMAXMIN),FDIST(IDFAMAX,IDMAXMIN),
+     &             SCCPHI(IDFAMAX,IDMAXMIN), SCCTHE(IDFAMAX,IDMAXMIN), 
+     &             SCCNEI(IDFAMAX,IDMAXMIN),
+     &             FPHI1(IDFAMAX,IDMAXMIN), FPHI2(IDFAMAX,IDMAXMIN),
+     &             FTHE1(IDFAMAX,IDMAXMIN), FTHE2(IDFAMAX,IDMAXMIN), 
+     &             DIS_INC, PHI_INC, THE_INC, NEI_INC, BETA_INC,
+     &             WSHET(MAXRES,MAXRES), EDFABET, 
+     &             CK(4),SCK(4),S1(4),S2(4)
+c    &             ,DFAEXP(15001),
+
+      DATA CK/1.0D0,1.58740105197D0,2.08008382305D0,2.51984209979D0/
+      DATA SCK/1.0D0,1.25992104989D0,1.44224957031D0,1.58740105197D0/
+      DATA S1/3.75D0,5.75D0,7.75D0,9.75D0/
+      DATA S2/4.25D0,6.25D0,8.25D0,10.25D0/
index 2deca8e..29c73f0 100644 (file)
@@ -7,6 +7,7 @@ C-----------------------------------------------------------------------
       common /ffield/ wsc,wscp,welec,wbond,wstrain,wtor,wtor_d,wang,
      &  wscloc,wcorr,wcorr4,wcorr5,wcorr6,wsccor,wel_loc,wturn3,wturn4,
      &  wturn6,wvdwpp,wsct,weights(n_ene),temp0,
+     &  wdfa_dist,wdfa_tor,wdfa_nei,wdfa_beta,
      &  scal14,cutoff_corr,delt_corr,r0_corr,ipot,n_ene_comp,
      &  rescale_mode
       common /potentials/ potname(5)
index 40131bd..bd38d1b 100644 (file)
      & d_a(3,0:MAXRES2),d_a_work(6*MAXRES),kinetic_force(MAXRES6),
      & Gsqrp(MAXRES2,MAXRES2),Gsqrm(MAXRES2,MAXRES2),
      & vtot(MAXRES2),Gvec(maxres2,maxres2),Geigen(maxres2)
+
+       real*8 odl(max_template,maxdim),sigma_odl(max_template,maxdim),
+     &    dih(max_template,maxres),sigma_dih(max_template,maxres)
+
+       integer ires_homo(maxdim),jres_homo(maxdim)
+
        double precision v_ini,d_time,d_time0,t_bath,tau_bath,
      & EK,potE,potEcomp(0:n_ene+4),totE,totT,amax,kinetic_T,dvmax,damax,
      & edriftmax,
@@ -28,7 +34,8 @@
       integer n_timestep,ntwx,ntwe,lang,count_reset_moment,
      & count_reset_vel,reset_fricmat,nfrag,npair,nfrag_back,
      & ifrag_back(3,maxfrag_back,maxprocs/20),ntime_split,ntime_split0,
-     & maxtime_split
+     & maxtime_split,lim_odl,lim_dih,link_start_homo,link_end_homo,
+     & idihconstr_start_homo,idihconstr_end_homo
       integer nresn,nyosh,nnos
       double precision glogs,qmass,vlogs,xlogs
       logical large,print_compon,tbf,rest,reset_moment,reset_vel,
@@ -38,6 +45,9 @@
       common /back_constr/ uconst_back,utheta,ugamma,uscdiff,
      & dutheta,dugamma,duscdiff,duscdiffx,
      & wfrag_back,nfrag_back,ifrag_back
+       common /homrestr/ odl,dih,sigma_dih,sigma_odl,
+     & lim_odl,lim_dih,ires_homo,jres_homo,link_start_homo,
+     & link_end_homo,idihconstr_start_homo,idihconstr_end_homo
       common /qmeas/ qfrag,qpair,qinfrag,qinpair,wfrag,wpair,eq_time,
      & Ucdfrag,Ucdpair,dUdconst,dUdxconst,dqwol,dxqwol,Uconst,
      & iset,mset,nset,usampl,ifrag,ipair,npair,nfrag
index 5151ff7..6546327 100644 (file)
@@ -90,7 +90,7 @@ C Max. number of conformations in the pool
       parameter (max_pool=10)
 C Number of energy components
       integer n_ene,n_ene2
-      parameter (n_ene=23,n_ene2=2*n_ene)
+      parameter (n_ene=28,n_ene2=2*n_ene)
 C Number of threads in deformation
       integer max_thread,max_thread2
       parameter (max_thread=4,max_thread2=2*max_thread)     
@@ -137,3 +137,6 @@ C to master; depends on nstex / ntwx ratio
 C Nose-Hoover chain - chain length and order of Yoshida algorithm
       integer maxmnh,maxyosh
       parameter(maxmnh=10,maxyosh=5)
+C Maximum number of templates in homology-modeling restraints
+      integer max_template
+      parameter(max_template=19)
index ea1d287..7990793 100644 (file)
@@ -54,7 +54,7 @@ C Max. number of conformations in Master's cache array
 C Max. number of conformations in the pool
       parameter (max_pool=10)
 C Number of energy components
-      parameter (n_ene=21,n_ene2=2*n_ene)
+      parameter (n_ene=22,n_ene2=2*n_ene)
 C Number of threads in deformation
       integer max_thread,max_thread2
       parameter (max_thread=4,max_thread2=2*max_thread)     
index a4558b9..2a68d39 100644 (file)
@@ -54,7 +54,7 @@ C Max. number of conformations in Master's cache array
 C Max. number of conformations in the pool
       parameter (max_pool=10)
 C Number of energy components
-      parameter (n_ene=21,n_ene2=2*n_ene)
+      parameter (n_ene=22,n_ene2=2*n_ene)
 C Number of threads in deformation
       integer max_thread,max_thread2
       parameter (max_thread=4,max_thread2=2*max_thread)     
index 34a5343..be6af9c 100644 (file)
@@ -1705,8 +1705,8 @@ ctime        call flush(iout)
           call xdrfint_(ixdrf, nss, iret) 
           do j=1,nss
            if (dyn_ss) then
-            call xdrfint(ixdrf, idssb(j)+nres, iret)
-            call xdrfint(ixdrf, jdssb(j)+nres, iret)
+            call xdrfint_(ixdrf, idssb(j)+nres, iret)
+            call xdrfint_(ixdrf, jdssb(j)+nres, iret)
            else
             call xdrfint_(ixdrf, ihpb(j), iret)
             call xdrfint_(ixdrf, jhpb(j), iret)
@@ -1996,9 +1996,14 @@ c     &                (d_restart1(j,i+2*nres*il),j=1,3)
               enddo
              endif
 #endif
-              call mpi_scatter(i2set,1,mpi_integer,
-     &           iset,1,mpi_integer,king,
-     &           CG_COMM,ierr) 
+c Corrected AL 8/19/2014: each processor needs whole iset array not only its
+c own element
+c              call mpi_scatter(i2set,1,mpi_integer,
+c     &           iset,1,mpi_integer,king,
+c     &           CG_COMM,ierr)
+              call mpi_bcast(i2set(0),nodes,mpi_integer,king,
+     &         CG_COMM,ierr)
+              iset=i2set(me)
 
            endif
 
diff --git a/source/unres/src_MD/Makefile_MPICH_PGI b/source/unres/src_MD/Makefile_MPICH_PGI
new file mode 100644 (file)
index 0000000..f55b08f
--- /dev/null
@@ -0,0 +1,126 @@
+FC= mpif90
+OPT =  -fast
+
+FFLAGS = -c ${OPT} 
+#FFLAGS = -c -g -C
+FFLAGS1 = -c  -g 
+FFLAGS2 = -c  -g -O0 
+FFLAGSE = -c  -fast -Minline=name:scalar2,scalar,transpose2,matvec2,prodmat3
+
+CFLAGS = -c -DLINUX -DPGI
+
+LIBS = xdrf/libxdrf.a
+
+ARCH = LINUX
+PP = /lib/cpp -P
+
+LIBS = xdrf/libxdrf.a
+
+ARCH = LINUX
+PP = /lib/cpp -P
+
+
+all: unres
+
+.SUFFIXES: .F
+.F.o:
+       ${FC} ${FFLAGS} ${CPPFLAGS} $*.F
+
+
+object = unres.o arcos.o cartprint.o chainbuild.o convert.o initialize_p.o \
+        matmult.o readrtns.o parmread.o gen_rand_conf.o printmat.o map.o \
+        pinorm.o randgens.o rescode.o intcor.o timing.o misc.o intlocal.o \
+        cartder.o checkder_p.o econstr_local.o energy_p_new_barrier.o \
+       energy_p_new-sep_barrier.o gradient_p.o minimize_p.o sumsld.o \
+        cored.o rmdd.o geomout.o readpdb.o regularize.o thread.o fitsq.o mcm.o \
+        mc.o bond_move.o refsys.o check_sc_distr.o check_bond.o contact.o djacob.o \
+        eigen.o blas.o add.o entmcm.o minim_mcmf.o \
+        MP.o compare_s1.o prng.o proc_proc.o\
+        banach.o rmsd.o elecont.o dihed_cons.o \
+        sc_move.o local_move.o \
+        intcartderiv.o lagrangian_lesyng.o\
+       stochfric.o kinetic_lesyng.o MD_A-MTS.o moments.o int_to_cart.o \
+        surfatom.o sort.o muca_md.o MREMD.o rattle.o gauss.o energy_split-sep.o \
+        q_measure.o gnmr1.o test.o ssMD.o
+
+GAB: CPPFLAGS = -DPROCOR -DLINUX -DPGI -DUNRES -DMP -DMPI \
+       -DSPLITELE -DLANG0 -DCRYST_BOND -DCRYST_THETA -DCRYST_SC
+GAB: BIN = /users/adam/bin/unres_PGI_MPI_GAB-r.exe
+GAB: ${object} xdrf/libxdrf.a
+       cc -o compinfo compinfo.c
+       ./compinfo | true
+       ${FC} ${FFLAGS} cinfo.f
+       ${FC} ${OPT} ${object} cinfo.o ${LIBS}  -o ${BIN}
+
+E0LL2Y: CPPFLAGS = -DPROCOR -DLINUX -DPGI -DUNRES -DMP -DMPI \
+       -DSPLITELE -DLANG0
+E0LL2Y: BIN = /users/adam/bin/unres_PGI_MPI_E0LL2Y-r.exe
+E0LL2Y: ${object} xdrf/libxdrf.a
+       cc -o compinfo compinfo.c
+       ./compinfo | true
+       ${FC} ${FFLAGS} cinfo.f
+       ${FC} ${OPT} ${object} cinfo.o ${LIBS}  -o ${BIN}
+
+xdrf/libxdrf.a:
+       cd xdrf && make
+
+
+clean:
+       /bin/rm -f *.o && /bin/rm -f compinfo && cd xdrf && make clean
+
+test.o: test.F
+       ${FC} ${FFLAGS} ${CPPFLAGS} test.F
+
+chainbuild.o: chainbuild.F
+       ${FC} ${FFLAGS} ${CPPFLAGS} chainbuild.F
+
+matmult.o: matmult.f
+       ${FC} ${FFLAGS} ${CPPFLAGS} matmult.f
+
+parmread.o : parmread.F
+       ${FC} ${FFLAGS} ${CPPFLAGS} parmread.F
+
+intcor.o : intcor.f
+       ${FC} ${FFLAGS} ${CPPFLAGS} intcor.f
+
+cartder.o : cartder.F
+       ${FC} ${FFLAGS} ${CPPFLAGS} cartder.F
+
+readpdb.o : readpdb.F
+       ${FC} ${FFLAGS2} ${CPPFLAGS} readpdb.F
+
+sumsld.o : sumsld.f
+       ${FC} ${FFLAGS} ${CPPFLAGS} sumsld.f
+        
+cored.o : cored.f
+       ${FC} ${FFLAGS1} ${CPPFLAGS} cored.f
+rmdd.o : rmdd.f
+       ${FC} ${FFLAGS} ${CPPFLAGS} rmdd.f
+
+energy_p_new_barrier.o : energy_p_new_barrier.F
+       ${FC} ${FFLAGSE} ${CPPFLAGS} energy_p_new_barrier.F
+
+gradient_p.o : gradient_p.F
+       ${FC} ${FFLAGSE} ${CPPFLAGS} gradient_p.F
+
+energy_p_new-sep_barrier.o : energy_p_new-sep_barrier.F
+       ${FC} ${FFLAGSE} ${CPPFLAGS} energy_p_new-sep_barrier.F
+
+lagrangian_lesyng.o : lagrangian_lesyng.F
+       ${FC} ${FFLAGSE} ${CPPFLAGS} lagrangian_lesyng.F
+
+MD_A-MTS.o : MD_A-MTS.F
+       ${FC} ${FFLAGSE} ${CPPFLAGS} MD_A-MTS.F
+
+blas.o : blas.f
+       ${FC} ${FFLAGS1} blas.f
+
+add.o : add.f
+       ${FC} ${FFLAGS1} add.f
+
+eigen.o : eigen.f
+       ${FC} ${FFLAGS2} eigen.f
+
+proc_proc.o: proc_proc.c
+       ${CC} ${CFLAGS} proc_proc.c
index c928a62..d763388 100644 (file)
@@ -40,7 +40,7 @@ object = unres.o arcos.o cartprint.o chainbuild.o convert.o initialize_p.o \
         intcartderiv.o lagrangian_lesyng.o\
        stochfric.o kinetic_lesyng.o MD_A-MTS.o moments.o int_to_cart.o \
         surfatom.o sort.o muca_md.o MREMD.o rattle.o gauss.o energy_split-sep.o \
-        q_measure.o gnmr1.o test.o ssMD.o
+        q_measure.o gnmr1.o test.o dfa.o ssMD.o
 
 no_option:
 
index be05bcd..b42001a 100644 (file)
@@ -1,29 +1,32 @@
 C DO NOT EDIT THIS FILE - IT HAS BEEN GENERATED BY COMPINFO.C
-C 3 2 110
+C 3 2 169
       subroutine cinfo
       include 'COMMON.IOUNITS'
       write(iout,*)'++++ Compile info ++++'
-      write(iout,*)'Version 3.2 build 110'
-      write(iout,*)'compiled Tue Apr 30 09:32:51 2013'
-      write(iout,*)'compiled by czarek@piasek3'
+      write(iout,*)'Version 3.2 build 169'
+      write(iout,*)'compiled Mon Jul 21 16:29:49 2014'
+      write(iout,*)'compiled by jal47@matrix.chem.cornell.edu'
       write(iout,*)'OS name:    Linux '
-      write(iout,*)'OS release: 2.6.32-45-generic '
+      write(iout,*)'OS release: 2.6.34.9-69.fc13.x86_64 '
       write(iout,*)'OS version:',
-     & ' #104-Ubuntu SMP Tue Feb 19 21:20:09 UTC 2013 '
+     & ' #1 SMP Tue May 3 09:23:03 UTC 2011 '
       write(iout,*)'flags:'
       write(iout,*)'INSTALL_DIR = /users/software/mpich-1.2.7p1_int...'
-      write(iout,*)'FC= ifort'
-      write(iout,*)'OPT =  -O3 -ip '
-      write(iout,*)'FFLAGS = -c ${OPT} -I$(INSTALL_DIR)/include '
-      write(iout,*)'FFLAGS1 = -c  -g -CA -CB -I$(INSTALL_DIR)/inclu...'
-      write(iout,*)'FFLAGS2 = -c  -g -O0 -I$(INSTALL_DIR)/include  '
-      write(iout,*)'FFLAGSE = -c  -O3 -ipo  -opt_report -I$(INSTALL...'
+      write(iout,*)'FC = ifort'
+      write(iout,*)'FFLAGS = -c ${OPT} -I$(INSTALL_DIR)/include'
+      write(iout,*)'FFLAGS1 = -c -w -g -d2 -CA -CB -I$(INSTALL_DIR)...'
+      write(iout,*)'FFLAGS2 = -c -w -g -O0 -I$(INSTALL_DIR)/include'
+      write(iout,*)'FFLAGS3 = -c -w -O3 -mp'
+      write(iout,*)'FFLAGSE = -c -w -O3 -ipo -ipo_obj  -opt_report ...'
+      write(iout,*)'CC = cc'
+      write(iout,*)'CFLAGS = -DLINUX -DPGI -c'
+      write(iout,*)'OPT =  -O3 -ip -w'
       write(iout,*)'LIBS = -L$(INSTALL_DIR)/lib -lmpich xdrf/libxdr...'
       write(iout,*)'ARCH = LINUX'
       write(iout,*)'PP = /lib/cpp -P'
       write(iout,*)'object = unres.o arcos.o cartprint.o chainbuild...'
       write(iout,*)'GAB: CPPFLAGS = -DPROCOR -DLINUX -DPGI -DUNRES ...'
-      write(iout,*)'GAB: BIN = ../../../bin/unres/MD/unres_ifort_MP...'
+      write(iout,*)'GAB: BIN = ../bin/unres_ifort_MPICH-restr-DFA_G...'
       write(iout,*)'E0LL2Y: CPPFLAGS = -DPROCOR -DLINUX -DPGI -DUNR...'
       write(iout,*)'E0LL2Y: BIN = ../../../bin/unres/MD/unres_ifort...'
       write(iout,*)'++++ End of compile info ++++'
diff --git a/source/unres/src_MD/dfa.F b/source/unres/src_MD/dfa.F
new file mode 100644 (file)
index 0000000..576910c
--- /dev/null
@@ -0,0 +1,3455 @@
+      subroutine init_dfa_vars
+
+      include 'DIMENSIONS'
+      include 'COMMON.INTERACT'
+      include 'COMMON.DFA'
+
+      integer ii
+
+C     Number of restraints
+      idisnum = 0
+      iphinum = 0
+      ithenum = 0
+      ineinum = 0
+      
+      idislis = 0
+      iphilis = 0
+      ithelis = 0
+      ineilis = 0
+      jneilis = 0
+      jneinum = 0
+      kshell  = 0
+      fnei    = 0
+C     For beta
+      nca     = 0
+      icaidx  = 0
+
+C     real variables
+CC    WEIGHTS for each min
+      sccdist = 0.0d0
+      fdist   = 0.0d0
+      sccphi  = 0.0d0
+      sccthe  = 0.0d0
+      sccnei  = 0.0d0
+      fphi1   = 0.0d0
+      fphi2   = 0.0d0
+      fthe1   = 0.0d0
+      fthe2   = 0.0d0
+C     energies
+      edfatot = 0.0d0
+      edfadis = 0.0d0
+      edfaphi = 0.0d0
+      edfathe = 0.0d0
+      edfanei = 0.0d0
+      edfabet = 0.0d0
+C     weights for each E term
+C     these should be identical with 
+      dis_inc = 0.0d0
+      phi_inc = 0.0d0
+      the_inc = 0.0d0
+      nei_inc = 0.0d0
+      beta_inc = 0.0d0
+      wshet   = 0.0d0
+C     precalculate exp table!
+c      dfaexp  = 0.0d0
+c      do ii = 1, 15001
+c         dfaexp(ii) = exp(-ii*0.001d0 + 0.0005d0)
+c      end do
+
+      ishiftca=nnt-1
+      ilastca=nct
+
+      print *,'ishiftca=',ishiftca,'ilastca=',ilastca
+
+      return
+      end
+
+      
+      subroutine read_dfa_info
+C
+C     read fragment informations
+C
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DFA'
+
+
+C     NOTE THAT FILENAMES are FIXED, CURRENTLY!!
+C     THIS SHOULD BE MODIFIED!!
+
+      character*320 buffer
+      integer iodfa
+      parameter(iodfa=89)
+
+      integer i, j, nval
+      integer ica1, ica2,ica3,ica4,ica5
+      integer ishell, inca, itmp,iitmp
+      double precision wtmp
+C
+C     READ DISTANCE
+C
+      open(iodfa, file = 'dist_dfa.dat', status = 'old', err=33)
+      goto 34
+ 33   write(iout,'(a)') 'Error opening dist_dfa.dat file'
+      stop
+ 34   continue
+      write(iout,'(a)') 'dist_dfa.dat is opened!'
+C     read title
+      read(iodfa, '(a)') buffer
+C     read number of restraints
+      read(iodfa, *) IDFADIS
+      read(iodfa, *) dis_inc
+      do i=1, idfadis
+         read(iodfa, '(i10,1x,i10,1x,i10)') ica1, ica2, nval
+
+         idisnum(i)=nval
+         idislis(1,i)=ica1
+         idislis(2,i)=ica2
+
+         do j=1, nval
+            read(iodfa,*) tmp
+            fdist(i,j) = tmp
+         enddo
+
+         do j=1, nval
+            read(iodfa,*) tmp
+            sccdist(i,j) = tmp
+         enddo
+         
+      enddo
+      close(iodfa)
+
+C     READ ANGLE RESTRAINTS
+C     PHI RESTRAINTS
+      open(iodfa, file='phi_dfa.dat',status='old',err=35)
+      goto 36
+ 35   write(iout,'(a)') 'Error opening dist_dfa.dat file'
+      stop
+
+ 36   continue
+      write(iout,'(a)') 'phi_dfa.dat is opened!'      
+
+C     READ TITLE
+      read(iodfa, '(a)') buffer
+C     READ NUMBER OF RESTRAINTS
+      READ(iodfa, *) IDFAPHI
+      read(iodfa,*) phi_inc
+      do i=1, idfaphi
+         read(iodfa,'(5(i10,1x),1x,i10)')ica1,ica2,ica3,ica4,ica5,nval
+
+         iphinum(i)=nval
+
+         iphilis(1,i)=ica1
+         iphilis(2,i)=ica2
+         iphilis(3,i)=ica3
+         iphilis(4,i)=ica4
+         iphilis(5,i)=ica5
+
+         do j=1, nval
+            read(iodfa,*) tmp1,tmp2
+            fphi1(i,j) = tmp1
+            fphi2(i,j) = tmp2
+         enddo
+
+         do j=1, nval
+            read(iodfa,*) tmp
+            sccphi(i,j) = tmp
+         enddo
+         
+      enddo
+      close(iodfa)
+
+C     THETA RESTRAINTS
+      open(iodfa, file='theta_dfa.dat',status='old',err=41)
+      goto 42
+ 41   write(iout,'(a)') 'Error opening dist_dfa.dat file'
+      stop
+ 42   continue
+      write(iout,'(a)') 'theta_dfa.dat is opened!'            
+C     READ TITLE
+      read(iodfa, '(a)') buffer
+C     READ NUMBER OF RESTRAINTS
+      READ(iodfa, *) IDFATHE
+      read(iodfa,*) the_inc
+
+      do i=1, idfathe
+         read(iodfa, '(5(i10,1x),1x,i10)')ica1,ica2,ica3,ica4,ica5,nval
+
+         ithenum(i)=nval
+
+         ithelis(1,i)=ica1
+         ithelis(2,i)=ica2
+         ithelis(3,i)=ica3
+         ithelis(4,i)=ica4
+         ithelis(5,i)=ica5
+
+         do j=1, nval
+            read(iodfa,*) tmp1,tmp2
+            fthe1(i,j) = tmp1
+            fthe2(i,j) = tmp2
+         enddo
+
+         do j=1, nval
+            read(iodfa,*) tmp
+            sccthe(i,j) = tmp
+         enddo
+         
+      enddo
+      close(iodfa)
+C     END of READING ANGLE RESTRAINT!
+
+C     NUMBER OF NEIGHBOR CAs
+      open(iodfa,file='nei_dfa.dat',status='old',err=37)
+      goto 38
+ 37   write(iout,'(a)') 'Error opening nei_dfa.dat file'
+      stop
+ 38   continue
+      write(iout,'(a)') 'nei_dfa.dat is opened!'
+C     READ TITLE
+      read(iodfa, '(a)') buffer
+C     READ NUMBER OF RESTRAINTS
+      READ(iodfa, *) idfanei
+      read(iodfa,*) nei_inc
+
+      do i=1, idfanei
+         read(iodfa,'(2(i10,1x),i10)')ica1,ishell,nval
+
+         ineilis(i)=ica1
+         kshell(i)=ishell
+         ineinum(i)=nval
+
+         do j=1, nval
+            read(iodfa,*) inca
+            fnei(i,j) = inca
+C            write(*,*) 'READ NEI:',i,j,fnei(i,j)
+         enddo
+
+         do j=1, nval
+            read(iodfa,*) tmp
+            sccnei(i,j) = tmp
+         enddo
+         
+      enddo
+      close(iodfa)
+C     END OF NEIGHBORING CA
+
+C     READ BETA RESTRAINT
+      open(iodfa, file='beta_dfa.dat',status='old',err=39)
+      goto 40
+ 39   write(iout,'(a)') 'Error opening beta_dfa.dat file'
+      stop
+ 40   continue
+      write(iout,'(a)') 'beta_dfa.dat is opened!'
+
+      read(iodfa,'(a)') buffer
+      read(iodfa,*) itmp
+      read(iodfa,*) beta_inc
+
+      do i=1,itmp
+         read(iodfa,*) ica1, iitmp
+         do j=1,itmp
+            read(iodfa,*) wtmp
+            wshet(i,j) =  wtmp
+c            write(*,*) 'BETA:',i,j,wtmp,wshet(i,j)
+         enddo
+      enddo
+      
+      close(iodfa)
+C     END OF BETA RESTRAINT
+      
+      return
+      END
+
+      subroutine edfad(edfadis)
+
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.DFA'
+
+      double precision edfadis
+      integer i, iatm1, iatm2,idiff
+      double precision ckk, sckk,dist,texp
+      double precision jix,jiy,jiz,ep,fp,scc
+      
+      edfadis=0
+      gdfad=0.0d0
+
+      do i=1, idfadis
+
+         iatm1=idislis(1,i)+ishiftca
+         iatm2=idislis(2,i)+ishiftca
+         idiff = abs(iatm1-iatm2)
+
+         JIX=c(1,iatm2)-c(1,iatm1)
+         JIY=c(2,iatm2)-c(2,iatm1)
+         JIZ=c(3,iatm2)-c(3,iatm1)
+         DIST=SQRT(JIX*JIX+JIY*JIY+JIZ*JIZ)
+         
+         ckk=ck(idiff)
+         sckk=sck(idiff)
+
+         scc = 0.0d0
+         ep = 0.0d0
+         fp = 0.0d0
+
+         do j=1,idisnum(i)
+            
+            dd = dist-fdist(i,j)
+            dtmp = dd*dd/ckk
+            if (dtmp.ge.15.0d0) then
+               texp = 0.0d0
+            else
+c               texp = dfaexp( idint(dtmp*1000)+1 )/sckk
+                texp = exp(-dtmp)/sckk
+            endif
+
+            ep=ep+sccdist(i,j)*texp
+            fp=fp+sccdist(i,j)*texp*dd*2.0d0/ckk
+            scc=scc+sccdist(i,j)
+C            write(*,'(2i8,6f12.5)') i, j, dist, 
+C     &           fdist(i,j), ep, fp, sccdist(i,j), scc
+
+         enddo
+         
+         ep = -ep/scc
+         fp = fp/scc
+
+
+c         IF(ABS(EP).lt.1.0d-20)THEN
+c            EP=0.0D0
+c         ENDIF
+c         IF (ABS(FP).lt.1.0d-20) THEN
+c            FP=0.0D0
+c         ENDIF
+         
+         edfadis=edfadis+ep*dis_inc*wwdist
+         
+         gdfad(1,iatm1) = gdfad(1,iatm1)-jix/dist*fp*dis_inc*wwdist
+         gdfad(2,iatm1) = gdfad(2,iatm1)-jiy/dist*fp*dis_inc*wwdist
+         gdfad(3,iatm1) = gdfad(3,iatm1)-jiz/dist*fp*dis_inc*wwdist
+
+         gdfad(1,iatm2) = gdfad(1,iatm2)+jix/dist*fp*dis_inc*wwdist
+         gdfad(2,iatm2) = gdfad(2,iatm2)+jiy/dist*fp*dis_inc*wwdist
+         gdfad(3,iatm2) = gdfad(3,iatm2)+jiz/dist*fp*dis_inc*wwdist
+
+      enddo
+
+      return
+      end
+      
+      subroutine edfat(edfator)
+C     DFA torsion angle
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.DFA'
+      
+      integer i,j,ii,iii
+      integer iatom(5)
+      double precision aphi(2),athe(2),tdx(5),tdy(5),tdz(5)
+      double precision cwidth, cwidth2
+      PARAMETER(CWIDTH=0.1D0,CWIDTH2=0.2D0,PAI=3.14159265358979323846D0)
+      
+      edfator= 0.0d0
+      enephi = 0.0d0
+      enethe = 0.0d0
+      gdfat(:,:) = 0.0d0
+
+C     START OF PHI ANGLE
+      do i=1, idfaphi
+
+         aphi = 0.0d0
+         do iii=1,5
+          iatom(iii)=iphilis(iii,i)+ishiftca
+         enddo
+         
+C     ANGLE VECTOR CALCULTION
+         RIX=C(1,IATOM(2))-C(1,IATOM(1))
+         RIY=C(2,IATOM(2))-C(2,IATOM(1))
+         RIZ=C(3,IATOM(2))-C(3,IATOM(1))
+              
+         RIPX=C(1,IATOM(3))-C(1,IATOM(2))
+         RIPY=C(2,IATOM(3))-C(2,IATOM(2))
+         RIPZ=C(3,IATOM(3))-C(3,IATOM(2))
+              
+         RIPPX=C(1,IATOM(4))-C(1,IATOM(3))
+         RIPPY=C(2,IATOM(4))-C(2,IATOM(3))
+         RIPPZ=C(3,IATOM(4))-C(3,IATOM(3))
+              
+         RIP3X=C(1,IATOM(5))-C(1,IATOM(4))
+         RIP3Y=C(2,IATOM(5))-C(2,IATOM(4))
+         RIP3Z=C(3,IATOM(5))-C(3,IATOM(4))
+         
+         GIX=RIY*RIPZ-RIZ*RIPY
+         GIY=RIZ*RIPX-RIX*RIPZ
+         GIZ=RIX*RIPY-RIY*RIPX
+              
+         GIPX=RIPY*RIPPZ-RIPZ*RIPPY
+         GIPY=RIPZ*RIPPX-RIPX*RIPPZ
+         GIPZ=RIPX*RIPPY-RIPY*RIPPX
+              
+         CIPX=C(1,IATOM(3))-C(1,IATOM(1))
+         CIPY=C(2,IATOM(3))-C(2,IATOM(1))
+         CIPZ=C(3,IATOM(3))-C(3,IATOM(1))
+         
+         CIPPX=C(1,IATOM(4))-C(1,IATOM(2))
+         CIPPY=C(2,IATOM(4))-C(2,IATOM(2))
+         CIPPZ=C(3,IATOM(4))-C(3,IATOM(2))
+         
+         CIP3X=C(1,IATOM(5))-C(1,IATOM(3))
+         CIP3Y=C(2,IATOM(5))-C(2,IATOM(3))
+         CIP3Z=C(3,IATOM(5))-C(3,IATOM(3))
+         
+         DGI=SQRT(GIX*GIX+GIY*GIY+GIZ*GIZ)
+         DGIP=SQRT(GIPX*GIPX+GIPY*GIPY+GIPZ*GIPZ)
+         DRIPP=SQRT(RIPPX*RIPPX+RIPPY*RIPPY+RIPPZ*RIPPZ)
+         DRIP3=SQRT(RIP3X*RIP3X+RIP3Y*RIP3Y+RIP3Z*RIP3Z)
+              
+C     END OF ANGLE VECTOR CALCULTION
+         
+         TDOT=GIX*RIPPX+GIY*RIPPY+GIZ*RIPPZ
+         APHI(1)=TDOT/(DGI*DRIPP)
+         TDOT=GIPX*RIP3X+GIPY*RIP3Y+GIPZ*RIP3Z
+         APHI(2)=TDOT/(DGIP*DRIP3)
+
+         ephi = 0.0d0
+         tfphi1=0.0d0
+         tfphi2=0.0d0
+         scc=0.0d0
+         
+         do j=1, iphinum(i)
+            DDPS1=APHI(1)-FPHI1(i,j)
+            DDPS2=APHI(2)-FPHI2(i,j)
+            
+            DTMP = (DDPS1**2+DDPS2**2)/CWIDTH2 
+            
+            if (dtmp.ge.15.0d0) then
+               ps_tmp = 0.0d0
+            else
+c               ps_tmp = dfaexp(idint(dtmp*1000)+1)
+                ps_tmp = exp(-dtmp)
+            endif
+            
+            ephi=ephi+sccphi(i,j)*ps_tmp
+            
+            tfphi1=tfphi1+sccphi(i,j)*ddps1/cwidth*ps_tmp
+            tfphi2=tfphi2+sccphi(i,j)*ddps2/cwidth*ps_tmp
+            
+            scc=scc+sccphi(i,j)
+C            write(*,'(2i8,8f12.6)')i,j,aphi(1),fphi1(i,j),
+C     &           aphi(2),fphi2(i,j),tfphi1,tfphi2,ephi,sccphi(i,j)
+         ENDDO
+         
+         ephi=-ephi/scc*phi_inc*wwangle
+         tfphi1=tfphi1/scc*phi_inc*wwangle
+         tfphi2=tfphi2/scc*phi_inc*wwangle
+         
+         IF (ABS(EPHI).LT.1d-20) THEN
+            EPHI=0.0D0
+         ENDIF
+         IF (ABS(TFPHI1).LT.1d-20) THEN
+            TFPHI1=0.0D0
+         ENDIF
+         IF (ABS(TFPHI2).LT.1d-20) THEN
+            TFPHI2=0.0D0
+         ENDIF
+
+C     FORCE DIRECTION CALCULATION
+         TDX(1:5)=0.0D0
+         TDY(1:5)=0.0D0
+         TDZ(1:5)=0.0D0
+         
+         DM1=1.0d0/(DGI*DRIPP)
+         
+         GIRPP=GIX*RIPPX+GIY*RIPPY+GIZ*RIPPZ
+         DM2=GIRPP/(DGI**3*DRIPP)
+         DM3=GIRPP/(DGI*DRIPP**3)
+         
+         DM4=1.0d0/(DGIP*DRIP3)
+         
+         GIRP3=GIPX*RIP3X+GIPY*RIP3Y+GIPZ*RIP3Z
+         DM5=GIRP3/(DGIP**3*DRIP3)
+         DM6=GIRP3/(DGIP*DRIP3**3)
+C     FIRST ATOM BY PHI1
+         TDX(1)=(RIPZ*RIPPY-RIPY*RIPPZ)*DM1
+     &        +( GIZ* RIPY- GIY* RIPZ)*DM2
+         TDY(1)=(RIPX*RIPPZ-RIPZ*RIPPX)*DM1
+     &        +( GIX* RIPZ- GIZ* RIPX)*DM2
+         TDZ(1)=(RIPY*RIPPX-RIPX*RIPPY)*DM1
+     &        +( GIY* RIPX- GIX* RIPY)*DM2
+         TDX(1)=TDX(1)*TFPHI1
+         TDY(1)=TDY(1)*TFPHI1
+         TDZ(1)=TDZ(1)*TFPHI1
+C     SECOND ATOM BY PHI1
+         TDX(2)=(CIPY*RIPPZ-CIPZ*RIPPY)*DM1
+     &        -(CIPY*GIZ-CIPZ*GIY)*DM2
+         TDY(2)=(CIPZ*RIPPX-CIPX*RIPPZ)*DM1
+     &        -(CIPZ*GIX-CIPX*GIZ)*DM2
+         TDZ(2)=(CIPX*RIPPY-CIPY*RIPPX)*DM1
+     &        -(CIPX*GIY-CIPY*GIX)*DM2
+         TDX(2)=TDX(2)*TFPHI1
+         TDY(2)=TDY(2)*TFPHI1
+         TDZ(2)=TDZ(2)*TFPHI1
+C     SECOND ATOM BY PHI2
+         TDX(2)=TDX(2)+
+     &        ((RIPPZ*RIP3Y-RIPPY*RIP3Z)*DM4
+     &        +( GIPZ*RIPPY- GIPY*RIPPZ)*DM5)*TFPHI2
+         TDY(2)=TDY(2)+
+     &        ((RIPPX*RIP3Z-RIPPZ*RIP3X)*DM4
+     &        +( GIPX*RIPPZ- GIPZ*RIPPX)*DM5)*TFPHI2
+         TDZ(2)=TDZ(2)+
+     &        ((RIPPY*RIP3X-RIPPX*RIP3Y)*DM4
+     &        +( GIPY*RIPPX- GIPX*RIPPY)*DM5)*TFPHI2
+C     THIRD ATOM BY PHI1
+         TDX(3)=(-GIX+RIPPY*RIZ-RIPPZ*RIY)*DM1
+     &        -(GIY*RIZ-RIY*GIZ)*DM2+RIPPX*DM3
+         TDY(3)=(-GIY+RIPPZ*RIX-RIPPX*RIZ)*DM1
+     &        -(GIZ*RIX-RIZ*GIX)*DM2+RIPPY*DM3
+         TDZ(3)=(-GIZ+RIPPX*RIY-RIPPY*RIX)*DM1
+     &        -(GIX*RIY-RIX*GIY)*DM2+RIPPZ*DM3
+         TDX(3)=TDX(3)*TFPHI1
+         TDY(3)=TDY(3)*TFPHI1
+         TDZ(3)=TDZ(3)*TFPHI1
+C     THIRD ATOM BY PHI2
+         TDX(3)=TDX(3)+
+     &        ((CIPPY*RIP3Z-CIPPZ*RIP3Y)*DM4
+     &        -(CIPPY*GIPZ-CIPPZ*GIPY)*DM5)*TFPHI2
+         TDY(3)=TDY(3)+
+     &        ((CIPPZ*RIP3X-CIPPX*RIP3Z)*DM4
+     &        -(CIPPZ*GIPX-CIPPX*GIPZ)*DM5)*TFPHI2
+         TDZ(3)=TDZ(3)+
+     &        ((CIPPX*RIP3Y-CIPPY*RIP3X)*DM4
+     &        -(CIPPX*GIPY-CIPPY*GIPX)*DM5)*TFPHI2
+C     FOURTH ATOM BY PHI1
+         TDX(4)=(GIX*DM1-RIPPX*DM3)*TFPHI1
+         TDY(4)=(GIY*DM1-RIPPY*DM3)*TFPHI1
+         TDZ(4)=(GIZ*DM1-RIPPZ*DM3)*TFPHI1
+C     FOURTH ATOM BY PHI2            
+         TDX(4)=TDX(4)+
+     &        ((-GIPX+RIP3Y*RIPZ-RIP3Z*RIPY)*DM4
+     &        -( GIPY*RIPZ-RIPY*GIPZ)*DM5
+     &        + RIP3X*DM6)*TFPHI2
+         TDY(4)=TDY(4)+
+     &        ((-GIPY+RIP3Z*RIPX-RIP3X*RIPZ)*DM4
+     &        -( GIPZ*RIPX-RIPZ*GIPX)*DM5
+     &        + RIP3Y*DM6)*TFPHI2
+         TDZ(4)=TDZ(4)+
+     &        ((-GIPZ+RIP3X*RIPY-RIP3Y*RIPX)*DM4
+     &        -( GIPX*RIPY-RIPX*GIPY)*DM5
+     &        + RIP3Z*DM6)*TFPHI2
+C     FIFTH ATOM BY PHI2
+         TDX(5)=(GIPX*DM4-RIP3X*DM6)*TFPHI2
+         TDY(5)=(GIPY*DM4-RIP3Y*DM6)*TFPHI2
+         TDZ(5)=(GIPZ*DM4-RIP3Z*DM6)*TFPHI2
+C     END OF FORCE DIRECTION
+c     force calcuation
+         DO II=1,5
+            gdfat(1,IATOM(II))=gdfat(1,IATOM(II))+TDX(II)
+            gdfat(2,IATOM(II))=gdfat(2,IATOM(II))+TDY(II)
+            gdfat(3,IATOM(II))=gdfat(3,IATOM(II))+TDZ(II)
+         ENDDO
+c     energy calculation
+         enephi = enephi + ephi
+c     end of single assignment statement
+      ENDDO
+C     END OF PHI RESTRAINT
+
+C     START OF THETA ANGLE
+      do i=1, idfathe
+
+         athe = 0.0d0
+         do iii=1,5
+          iatom(iii)=ithelis(iii,i)+ishiftca
+         enddo
+
+         
+C     ANGLE VECTOR CALCULTION
+         RIX=C(1,IATOM(2))-C(1,IATOM(1))
+         RIY=C(2,IATOM(2))-C(2,IATOM(1))
+         RIZ=C(3,IATOM(2))-C(3,IATOM(1))
+              
+         RIPX=C(1,IATOM(3))-C(1,IATOM(2))
+         RIPY=C(2,IATOM(3))-C(2,IATOM(2))
+         RIPZ=C(3,IATOM(3))-C(3,IATOM(2))
+         
+         RIPPX=C(1,IATOM(4))-C(1,IATOM(3))
+         RIPPY=C(2,IATOM(4))-C(2,IATOM(3))
+         RIPPZ=C(3,IATOM(4))-C(3,IATOM(3))
+         
+         RIP3X=C(1,IATOM(5))-C(1,IATOM(4))
+         RIP3Y=C(2,IATOM(5))-C(2,IATOM(4))
+         RIP3Z=C(3,IATOM(5))-C(3,IATOM(4))
+         
+         GIX=RIY*RIPZ-RIZ*RIPY
+         GIY=RIZ*RIPX-RIX*RIPZ
+         GIZ=RIX*RIPY-RIY*RIPX
+         
+         GIPX=RIPY*RIPPZ-RIPZ*RIPPY
+         GIPY=RIPZ*RIPPX-RIPX*RIPPZ
+         GIPZ=RIPX*RIPPY-RIPY*RIPPX
+         
+         GIPPX=RIPPY*RIP3Z-RIPPZ*RIP3Y
+         GIPPY=RIPPZ*RIP3X-RIPPX*RIP3Z
+         GIPPZ=RIPPX*RIP3Y-RIPPY*RIP3X
+         
+         CIPX=C(1,IATOM(3))-C(1,IATOM(1))
+         CIPY=C(2,IATOM(3))-C(2,IATOM(1))
+         CIPZ=C(3,IATOM(3))-C(3,IATOM(1))
+         
+         CIPPX=C(1,IATOM(4))-C(1,IATOM(2))
+         CIPPY=C(2,IATOM(4))-C(2,IATOM(2))
+         CIPPZ=C(3,IATOM(4))-C(3,IATOM(2))
+         
+         CIP3X=C(1,IATOM(5))-C(1,IATOM(3))
+         CIP3Y=C(2,IATOM(5))-C(2,IATOM(3))
+         CIP3Z=C(3,IATOM(5))-C(3,IATOM(3))
+         
+         DGI=SQRT(GIX*GIX+GIY*GIY+GIZ*GIZ)
+         DGIP=SQRT(GIPX*GIPX+GIPY*GIPY+GIPZ*GIPZ)
+         DGIPP=SQRT(GIPPX*GIPPX+GIPPY*GIPPY+GIPPZ*GIPPZ)
+         DRIPP=SQRT(RIPPX*RIPPX+RIPPY*RIPPY+RIPPZ*RIPPZ)
+         DRIP3=SQRT(RIP3X*RIP3X+RIP3Y*RIP3Y+RIP3Z*RIP3Z)
+C     END OF ANGLE VECTOR CALCULTION
+         
+         TDOT=GIX*GIPX+GIY*GIPY+GIZ*GIPZ
+         ATHE(1)=TDOT/(DGI*DGIP)
+         TDOT=GIPX*GIPPX+GIPY*GIPPY+GIPZ*GIPPZ
+         ATHE(2)=TDOT/(DGIP*DGIPP)
+         
+         ETHE=0.0D0
+         TFTHE1=0.0D0
+         TFTHE2=0.0D0
+         SCC=0.0D0
+         TH_TMP=0.0d0
+
+         do j=1,ithenum(i)
+            ddth1=athe(1)-fthe1(i,j) !cos(the1)-cos(the1_ref)
+            ddth2=athe(2)-fthe2(i,j) !cos(the2)-cos(the2_ref)
+            dtmp= (ddth1**2+ddth2**2)/cwidth2                 
+            if ( dtmp .ge. 15.0d0) then
+               th_tmp = 0.0d0
+            else
+c               th_tmp = dfaexp ( idint(dtmp*1000)+1 )
+               th_tmp = exp(-dtmp)
+            end if
+            
+            ethe=ethe+sccthe(i,j)*th_tmp
+
+            tfthe1=tfthe1+sccthe(i,j)*ddth1/cwidth*th_tmp !-dv/dcos(the1)
+            tfthe2=tfthe2+sccthe(i,j)*ddth2/cwidth*th_tmp !-dv/dcos(the2)
+            scc=scc+sccthe(i,j)
+C            write(*,'(2i8,8f12.6)')i,j,athe(1),fthe1(i,j),
+C     &           athe(2),fthe2(i,j),tfthe1,tfthe2,ethe,sccthe(i,j)
+         enddo
+         
+         ethe=-ethe/scc*the_inc*wwangle
+         tfthe1=tfthe1/scc*the_inc*wwangle
+         tfthe2=tfthe2/scc*the_inc*wwangle
+         
+         IF (ABS(ETHE).LT.TENM20) THEN
+            ETHE=0.0D0
+         ENDIF
+         IF (ABS(TFTHE1).LT.TENM20) THEN
+            TFTHE1=0.0D0
+         ENDIF
+         IF (ABS(TFTHE2).LT.TENM20) THEN
+            TFTHE2=0.0D0
+         ENDIF
+
+         TDX(1:5)=0.0D0
+         TDY(1:5)=0.0D0
+         TDZ(1:5)=0.0D0
+
+         DM1=1.0d0/(DGI*DGIP)
+         DM2=(GIX*GIPX+GIY*GIPY+GIZ*GIPZ)/(DGI**3*DGIP)
+         DM3=(GIX*GIPX+GIY*GIPY+GIZ*GIPZ)/(DGI*DGIP**3)
+         
+         DM4=1.0d0/(DGIP*DGIPP)
+         DM5=(GIPX*GIPPX+GIPY*GIPPY+GIPZ*GIPPZ)/(DGIP**3*DGIPP)
+         DM6=(GIPX*GIPPX+GIPY*GIPPY+GIPZ*GIPPZ)/(DGIP*DGIPP**3)
+
+C     FIRST ATOM BY THETA1
+         TDX(1)=((RIPZ*GIPY-RIPY*GIPZ)*DM1
+     &        -(GIY*RIPZ-GIZ*RIPY)*DM2)*TFTHE1
+         TDY(1)=((-RIPZ*GIPX+RIPX*GIPZ)*DM1
+     &        -(-GIX*RIPZ+GIZ*RIPX)*DM2)*TFTHE1
+         TDZ(1)=((RIPY*GIPX-RIPX*GIPY)*DM1
+     &        -(GIX*RIPY-GIY*RIPX)*DM2)*TFTHE1
+C     SECOND ATOM BY THETA1
+         TDX(2)=((CIPY*GIPZ-CIPZ*GIPY-RIPPY*GIZ+RIPPZ*GIY)*DM1
+     &        -(CIPY*GIZ-CIPZ*GIY)*DM2
+     &        +(RIPPY*GIPZ-RIPPZ*GIPY)*DM3)*TFTHE1
+         TDY(2)=((CIPZ*GIPX-CIPX*GIPZ-RIPPZ*GIX+RIPPX*GIZ)*DM1
+     &        -(CIPZ*GIX-CIPX*GIZ)*DM2
+     &        +(RIPPZ*GIPX-RIPPX*GIPZ)*DM3)*TFTHE1
+         TDZ(2)=((CIPX*GIPY-CIPY*GIPX-RIPPX*GIY+RIPPY*GIX)*DM1
+     &        -(CIPX*GIY-CIPY*GIX)*DM2
+     &        +(RIPPX*GIPY-RIPPY*GIPX)*DM3)*TFTHE1
+C     SECOND ATOM BY THETA2
+         TDX(2)=TDX(2)+
+     &        ((RIPPZ*GIPPY-RIPPY*GIPPZ)*DM4
+     &        -(GIPY*RIPPZ-GIPZ*RIPPY)*DM5)*TFTHE2
+         TDY(2)=TDY(2)+
+     &        ((-RIPPZ*GIPPX+RIPPX*GIPPZ)*DM4
+     &        -(-GIPX*RIPPZ+GIPZ*RIPPX)*DM5)*TFTHE2
+         TDZ(2)=TDZ(2)+
+     &        ((RIPPY*GIPPX-RIPPX*GIPPY)*DM4
+     &        -(GIPX*RIPPY-GIPY*RIPPX)*DM5)*TFTHE2
+C     THIRD ATOM BY THETA1
+         TDX(3)=((GIPY*RIZ-GIPZ*RIY-GIY*CIPPZ+GIZ*CIPPY)*DM1
+     &        -(GIY*RIZ-GIZ*RIY)*DM2
+     &        -(CIPPY*GIPZ-CIPPZ*GIPY)*DM3) *TFTHE1
+         TDY(3)=((GIPZ*RIX-GIPX*RIZ-GIZ*CIPPX+GIX*CIPPZ)*DM1
+     &        -(GIZ*RIX-GIX*RIZ)*DM2
+     &        -(CIPPZ*GIPX-CIPPX*GIPZ)*DM3) *TFTHE1
+         TDZ(3)=((GIPX*RIY-GIPY*RIX-GIX*CIPPY+GIY*CIPPX)*DM1
+     &        -(GIX*RIY-GIY*RIX)*DM2
+     &        -(CIPPX*GIPY-CIPPY*GIPX)*DM3) *TFTHE1
+C     THIRD ATOM BY THETA2
+         TDX(3)=TDX(3)+
+     &        ((CIPPY*GIPPZ-CIPPZ*GIPPY-RIP3Y*GIPZ+RIP3Z*GIPY)*DM4
+     &        -(CIPPY*GIPZ-CIPPZ*GIPY)*DM5
+     &        +(RIP3Y*GIPpZ-RIP3Z*GIPpY)*DM6) *TFTHE2
+         TDY(3)=TDY(3)+
+     &        ((CIPPZ*GIPPX-CIPPX*GIPPZ-RIP3Z*GIPX+RIP3X*GIPZ)*DM4
+     &        -(CIPPZ*GIPX-CIPPX*GIPZ)*DM5
+     &        +(RIP3Z*GIPpX-RIP3X*GIPpZ)*DM6) *TFTHE2
+         TDZ(3)=TDZ(3)+
+     &        ((CIPPX*GIPPY-CIPPY*GIPPX-RIP3X*GIPY+RIP3Y*GIPX)*DM4
+     &        -(CIPPX*GIPY-CIPPY*GIPX)*DM5
+     &        +(RIP3X*GIPpY-RIP3Y*GIPpX)*DM6) *TFTHE2
+C     FOURTH ATOM BY THETA1
+         TDX(4)=-((GIZ*RIPY-GIY*RIPZ)*DM1
+     &        -(GIPZ*RIPY-GIPY*RIPZ)*DM3) *TFTHE1
+         TDY(4)=-((GIX*RIPZ-GIZ*RIPX)*DM1
+     &        -(GIPX*RIPZ-GIPZ*RIPX)*DM3) *TFTHE1
+         TDZ(4)=-((GIY*RIPX-GIX*RIPY)*DM1
+     &        -(GIPY*RIPX-GIPX*RIPY)*DM3) *TFTHE1
+C     FOURTH ATOM BY THETA2
+         TDX(4)=TDX(4)+
+     &        ((GIPPY*RIPZ-GIPPZ*RIPY-GIPY*CIP3Z+GIPZ*CIP3Y)*DM4
+     &        -(GIPY*RIPZ-GIPZ*RIPY)*DM5
+     &        -(CIP3Y*GIPPZ-CIP3Z*GIPPY)*DM6)*TFTHE2
+         TDY(4)=TDY(4)+
+     &        ((GIPPZ*RIPX-GIPPX*RIPZ-GIPZ*CIP3X+GIPX*CIP3Z)*DM4
+     &        -(GIPZ*RIPX-GIPX*RIPZ)*DM5
+     &        -(CIP3Z*GIPPX-CIP3X*GIPPZ)*DM6)*TFTHE2
+         TDZ(4)=TDZ(4)+
+     &        ((GIPPX*RIPY-GIPPY*RIPX-GIPX*CIP3Y+GIPY*CIP3X)*DM4
+     &        -(GIPX*RIPY-GIPY*RIPX)*DM5
+     &        -(CIP3X*GIPPY-CIP3Y*GIPPX)*DM6)*TFTHE2
+C     FIFTH ATOM BY THETA2
+         TDX(5)=-((GIPZ*RIPPY-GIPY*RIPPZ)*DM4
+     &        -(GIPPZ*RIPPY-GIPPY*RIPPZ)*DM6)*TFTHE2
+         TDY(5)=-((GIPX*RIPPZ-GIPZ*RIPPX)*DM4
+     &        -(GIPPX*RIPPZ-GIPPZ*RIPPX)*DM6)*TFTHE2
+         TDZ(5)=-((GIPY*RIPPX-GIPX*RIPPY)*DM4
+     &        -(GIPPY*RIPPX-GIPPX*RIPPY)*DM6)*TFTHE2
+C     !! END OF FORCE DIRECTION!!!!
+         DO II=1,5
+            gdfat(1,iatom(II))=gdfat(1,iatom(II))+TDX(II)
+            gdfat(2,iatom(II))=gdfat(2,iatom(II))+TDY(II)
+            gdfat(3,iatom(II))=gdfat(3,iatom(II))+TDZ(II)
+         ENDDO
+C     energy calculation
+         enethe = enethe + ethe
+      ENDDO
+
+      edfator = enephi + enethe
+      
+      RETURN
+      END
+      
+      subroutine edfan(edfanei)
+C     DFA neighboring CA restraint
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.DFA'
+      
+      integer i,j,imin
+      integer kshnum, n1atom
+
+      double precision enenei,tmp_n
+      double precision pai,hpai
+      double precision jix,jiy,jiz,ndiff,snorm_nei
+      double precision t2dx(maxres),t2dy(maxres),t2dz(maxres)
+      double precision dr,dr2,half,ntmp,dtmp
+
+      parameter(dr=0.25d0,dr2=0.50d0,half=0.50d0)
+      parameter(pai=3.14159265358979323846D0)
+      parameter(hpai=1.5707963267948966D0)
+      parameter(snorm_nei=0.886226925452758D0)
+
+      edfanei = 0.0d0
+      enenei  = 0.0d0
+      gdfan   = 0.0d0
+
+c      print*, 's1:', s1(:)
+c      print*, 's2:', s2(:)
+
+      do i=1, idfanei
+
+         kshnum=kshell(i)
+         n1atom=ineilis(i)+ishiftca
+C         write(*,*) 'kshnum,n1atom:', kshnum, n1atom
+         
+         tmp_n=0.0d0
+         ftmp=0.0d0
+         dnei=0.0d0
+         dist=0.0d0            
+         t1dx=0.0d0
+         t1dy=0.0d0
+         t1dz=0.0d0
+         t2dx=0.0d0
+         t2dy=0.0d0
+         t2dz=0.0d0
+
+         do j = ishiftca+1, ilastca
+
+            if (n1atom.eq.j) cycle
+
+            jix=c(1,j)-c(1,n1atom)
+            jiy=c(2,j)-c(2,n1atom)
+            jiz=c(3,j)-c(3,n1atom)
+            dist=sqrt(jix*jix+jiy*jiy+jiz*jiz)
+
+c            write(*,*) n1atom, j, dist
+
+            if(kshnum.ne.1)then
+               if (dist.lt.s1(kshnum).and.
+     &              dist.gt.s2(kshnum-1)) then
+                  
+                  tmp_n=tmp_n+1.0d0
+
+c                  write(*,*) 'case1:',tmp_n
+
+                  t1dx=t1dx+0.0d0
+                  t1dy=t1dy+0.0d0
+                  t1dz=t1dz+0.0d0
+                  t2dx(j)=0.0d0
+                  t2dy(j)=0.0d0
+                  t2dz(j)=0.0d0
+                  
+               elseif(dist.ge.s1(kshnum).and.
+     &                 dist.le.s2(kshnum)) then
+
+                  dnei=(dist-s1(kshnum))/dr2*pai
+                  tmp_n=tmp_n + half*(1+cos(dnei))
+c                  write(*,*) 'case2:',tmp_n
+                  ftmp=-pai*sin(dnei)/dr2/dist/2.0d0
+c     center atom
+                  t1dx=t1dx+jix*ftmp
+                  t1dy=t1dy+jiy*ftmp
+                  t1dz=t1dz+jiz*ftmp
+c     neighbor atoms
+                  t2dx(j)=-jix*ftmp
+                  t2dy(j)=-jiy*ftmp
+                  t2dz(j)=-jiz*ftmp
+c     
+               elseif(dist.ge.s1(kshnum-1).and.
+     &                 dist.le.s2(kshnum-1)) then
+                  dnei=(dist-s1(kshnum-1))/dr2*pai
+                  tmp_n=tmp_n + 1.0d0 - half*(1+cos(dnei))
+c                  write(*,*) 'case3:',tmp_n
+                  ftmp = hpai*sin(dnei)/dr2/dist
+c     center atom
+                  t1dx=t1dx+jix*ftmp
+                  t1dy=t1dy+jiy*ftmp
+                  t1dz=t1dz+jiz*ftmp
+c     neighbor atoms
+                  t2dx(j)=-jix*ftmp
+                  t2dy(j)=-jiy*ftmp
+                  t2dz(j)=-jiz*ftmp
+                  
+               endif
+
+            elseif(kshnum.eq.1) then
+
+               if(dist.lt.s1(kshnum))then
+
+                  tmp_n=tmp_n+1.0d0
+c                  write(*,*) 'case4:',tmp_n
+                  t1dx=t1dx+0.0d0
+                  t1dy=t1dy+0.0d0
+                  t1dz=t1dz+0.0d0
+                  t2dx(j)=0.0d0
+                  t2dy(j)=0.0d0
+                  t2dz(j)=0.0d0
+
+               elseif(dist.ge.s1(kshnum).and.
+     &                 dist.le.s2(kshnum))then
+
+                  dnei=(dist-s1(kshnum))/dr2*pai
+                  tmp_n=tmp_n + half*(1+cos(dnei))
+c                  write(*,*) 'case5:',tmp_n
+                  ftmp = -hpai*sin(dnei)/dr2/dist
+c     center atom
+                  t1dx=t1dx+jix*ftmp
+                  t1dy=t1dy+jiy*ftmp
+                  t1dz=t1dz+jiz*ftmp
+c     neighbor atoms
+                  t2dx(j)=-jix*ftmp
+                  t2dy(j)=-jiy*ftmp
+                  t2dz(j)=-jiz*ftmp
+
+               endif
+            endif
+         enddo
+         
+         scc=0.0d0
+         enei=0.0d0
+         tmp_fnei=0.0d0
+         ndiff=0.0d0
+         
+         do imin=1,ineinum(i)
+
+            ndiff = tmp_n-fnei(i,imin)
+            dtmp  = ndiff*ndiff
+            
+            if (dtmp.ge.15.0d0) then
+               ntmp = 0.0d0
+            else
+c               ntmp = dfaexp( idint(dtmp*1000) + 1 ) 
+                ntmp = exp(-dtmp)
+            end if
+
+            enei=enei+sccnei(i,imin)*ntmp
+            tmp_fnei=tmp_fnei-
+     &           sccnei(i,imin)*ntmp*ndiff*2.0d0
+            scc=scc+sccnei(i,imin)
+
+c            write(*,'(a,1x,2i8,f12.7,i8,3f12.7)')'NEI:',i,imin,tmp_n,
+c     &           fnei(i,imin),sccnei(i,imin),enei,scc
+         enddo
+         
+         enei=-enei/scc*snorm_nei*nei_inc*wwnei
+         tmp_fnei=tmp_fnei/scc*snorm_nei*nei_inc*wwnei
+         
+c         if (abs(enei).lt.1.0d-20)then
+c            enei=0.0d0
+c         endif
+c         if (abs(tmp_fnei).lt.1.0d-20) then
+c            tmp_fnei=0.0d0
+c         endif
+         
+c     force calculation
+         t1dx=t1dx*tmp_fnei
+         t1dy=t1dy*tmp_fnei
+         t1dz=t1dz*tmp_fnei
+         
+         do j=ishiftca+1,ilastca
+            t2dx(j)=t2dx(j)*tmp_fnei
+            t2dy(j)=t2dy(j)*tmp_fnei
+            t2dz(j)=t2dz(j)*tmp_fnei
+         enddo
+         
+         gdfan(1,n1atom)=gdfan(1,n1atom)+t1dx
+         gdfan(2,n1atom)=gdfan(2,n1atom)+t1dy
+         gdfan(3,n1atom)=gdfan(3,n1atom)+t1dz
+         
+         do j=ishiftca+1,ilastca
+            gdfan(1,j)=gdfan(1,j)+t2dx(j)
+            gdfan(2,j)=gdfan(2,j)+t2dy(j)
+            gdfan(3,j)=gdfan(3,j)+t2dz(j)
+         enddo
+c     energy calculation
+
+         enenei=enenei+enei
+
+      enddo
+      
+      edfanei=enenei
+      
+      return
+      end
+      
+      subroutine edfab(edfabeta)
+
+      implicit real*8 (a-h,o-z)      
+
+      include 'DIMENSIONS'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.DFA'
+
+      real*8 PAI
+      parameter(PAI=3.14159265358979323846D0)
+      parameter (maxca=800)
+C     sheet variables
+      real*8 bx(maxres),by(maxres),bz(maxres)
+      real*8 vbet(maxres,maxres)
+      real*8 shetfx(maxres),shetfy(maxres),shetfz(maxres)
+      real*8 shefx(maxres,12),shefy(maxres,12),shefz(maxres,12)
+      real*8 vbeta,vbetp,vbetm
+      real*8 dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     &     c00,s00,ulnex,dnex
+      real*8 dp45,dm45,w_beta
+
+      real*8 cph(maxca),cth(maxca)
+      real*8 atx(maxca),aty(maxca),atz(maxca)
+      real*8 atmx(maxca),atmy(maxca),atmz(maxca)
+      real*8 atmmx(maxca),atmmy(maxca),atmmz(maxca)
+      real*8 atm3x(maxca),atm3y(maxca),atm3z(maxca)
+      real*8 sth(maxca)
+      real*8 astx(maxca),asty(maxca),astz(maxca)
+      real*8 astmx(maxca),astmy(maxca),astmz(maxca)
+      real*8 astmmx(maxca),astmmy(maxca),astmmz(maxca)
+      real*8 astm3x(maxca),astm3y(maxca),astm3z(maxca)
+      
+      real*8 atxnum(maxca),atynum(maxca),atznum(maxca),
+     & astxnum(maxca),astynum(maxca),astznum(maxca),
+     & atmxnum(maxca),atmynum(maxca),atmznum(maxca),
+     & astmxnum(maxca),astmynum(maxca),astmznum(maxca),
+     & atmmxnum(maxca),atmmynum(maxca),atmmznum(maxca),
+     & astmmxnum(maxca),astmmynum(maxca),astmmznum(maxca),
+     & atm3xnum(maxca),atm3ynum(maxca),atm3znum(maxca),
+     & astm3xnum(maxca),astm3ynum(maxca),astm3znum(maxca),
+     & cth_orig(maxca),sth_orig(maxca)
+
+      common /sheca/     bx,by,bz
+      common /shee/      vbeta,vbet,vbetp,vbetm  
+      common /shetf/     shetfx,shetfy,shetfz
+      common /shef/      shefx, shefy, shefz
+      common /sheparm/   dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     &                   c00,s00,ulnex,dnex
+      common /sheconst/  dp45,dm45,w_beta
+
+      common /angvt/ atx,aty,atz,atmx,atmy,atmz,atmmx,atmmy,
+     $     atmmz,atm3x,atm3y,atm3z
+      common /angvt2/ astx,asty,astz,astmx,astmy,astmz,astmmx,astmmy,
+     $     astmmz,astm3x,astm3y,astm3z
+
+      common /coscos/   cph,cth
+      common /sinsin/ sth
+
+C     End of sheet variables
+      
+      integer i,j
+      double precision enebet
+
+      enebet=0.0d0
+      bx=0.0d0;by=0.0d0;bz=0.0d0
+      shetfx=0.0d0;shetfy=0.0d0;shetfz=0.0d0
+
+      gdfab=0.0d0
+
+      do i=ishiftca+1,ilastca
+         bx(i-ishiftca)=c(1,i)
+         by(i-ishiftca)=c(2,i)
+         bz(i-ishiftca)=c(3,i)
+      enddo
+
+c      do i=1,ilastca-ishiftca
+c         read(99,*) bx(i),by(i),bz(i)
+c      enddo
+c      close(99)
+
+      dca=0.25d0**2
+      dshe=0.3d0**2
+      ULHB=5.0D0
+      ULDHB=5.0D0
+      ULNEX=COS(60.0D0/180.0D0*PAI)
+           
+      DLHB=1.0D0
+      DLDHB=1.0D0
+      
+      DNEX=0.3D0**2
+      
+      C00=COS((1.0D0+10.0D0/180.0D0)*PAI)
+      S00=SIN((1.0D0+10.0D0/180.0D0)*PAI)
+
+      W_BETA=0.5D0
+      DP45=W_BETA
+      DM45=W_BETA
+
+C     END OF INITIALIZATION
+
+      nca=ilastca-ishiftca
+
+      call angvectors(nca)
+      call sheetforce(nca,wshet)
+
+c     end of sheet energy and force
+
+      do j=1,nca
+         shetfx(j)=shetfx(j)*beta_inc
+         shetfy(j)=shetfy(j)*beta_inc
+         shetfz(j)=shetfz(j)*beta_inc
+c         write(*,*)'SHETF:',shetfx(j),shetfy(j),shetfz(j)
+      enddo
+
+      vbeta=vbeta*beta_inc
+      enebet=vbeta
+      edfabeta=enebet
+
+      do j=1,nca
+         gdfab(1,j+ishiftca)=gdfab(1,j+ishiftca)-shetfx(j)
+         gdfab(2,j+ishiftca)=gdfab(2,j+ishiftca)-shetfy(j)
+         gdfab(3,j+ishiftca)=gdfab(3,j+ishiftca)-shetfz(j)
+      enddo
+
+#ifdef DEBUG1
+      do j=1,nca
+        write(*,'(5x,i5,10x,3f10.5)') j,bx(j),by(j),bz(j)
+      enddo
+
+
+      gdfab=0
+      dinc=0.001
+      do j=1,nca
+        cth_orig(j)=cth(j)
+        sth_orig(j)=sth(j)
+      enddo
+
+      do j=1,nca
+
+       bx(j)=bx(j)+dinc
+       call angvectors(nca)
+       bx(j)=bx(j)-2*dinc
+       call angvectors(nca)
+       atxnum(j)=0.5*(cth(j)-cth_orig(j))/dinc
+       astxnum(j)=0.5*(sth(j)-sth_orig(j))/dinc
+       if (j.gt.1) then
+       atmxnum(j)=0.5*(cth(j-1)-cth_orig(j-1))/dinc
+       astmxnum(j)=0.5*(sth(j-1)-sth_orig(j-1))/dinc
+       endif
+       if (j.gt.2) then
+       atmmxnum(j)=0.5*(cth(j-2)-cth_orig(j-2))/dinc
+       astmmxnum(j)=0.5*(sth(j-2)-sth_orig(j-2))/dinc
+       endif
+       if (j.gt.3) then
+       atm3xnum(j)=0.5*(cth(j-3)-cth_orig(j-3))/dinc
+       astm3xnum(j)=0.5*(sth(j-3)-sth_orig(j-3))/dinc
+       endif
+       bx(j)=bx(j)+dinc
+       by(j)=by(j)+dinc
+       call angvectors(nca)
+       by(j)=by(j)-2*dinc
+       call angvectors(nca)
+       by(j)=by(j)+dinc
+       atynum(j)=0.5*(cth(j)-cth_orig(j))/dinc
+       astynum(j)=0.5*(sth(j)-sth_orig(j))/dinc
+       if (j.gt.1) then
+       atmynum(j)=0.5*(cth(j-1)-cth_orig(j-1))/dinc
+       astmynum(j)=0.5*(sth(j-1)-sth_orig(j-1))/dinc
+       endif
+       if (j.gt.2) then
+       atmmynum(j)=0.5*(cth(j-2)-cth_orig(j-2))/dinc
+       astmmynum(j)=0.5*(sth(j-2)-sth_orig(j-2))/dinc
+       endif
+       if (j.gt.3) then
+       atm3ynum(j)=0.5*(cth(j-3)-cth_orig(j-3))/dinc
+       astm3ynum(j)=0.5*(sth(j-3)-sth_orig(j-3))/dinc
+       endif
+
+       bz(j)=bz(j)+dinc
+       call angvectors(nca)
+       bz(j)=bz(j)-2*dinc
+       call angvectors(nca)
+       bz(j)=bz(j)+dinc
+
+       atznum(j)=0.5*(cth(j)-cth_orig(j))/dinc
+       astznum(j)=0.5*(sth(j)-sth_orig(j))/dinc
+       if (j.gt.1) then
+       atmznum(j)=0.5*(cth(j-1)-cth_orig(j-1))/dinc
+       astmznum(j)=0.5*(sth(j-1)-sth_orig(j-1))/dinc
+       endif
+       if (j.gt.2) then
+       atmmznum(j)=0.5*(cth(j-2)-cth_orig(j-2))/dinc
+       astmmznum(j)=0.5*(sth(j-2)-sth_orig(j-2))/dinc
+       endif
+       if (j.gt.3) then
+       atm3znum(j)=0.5*(cth(j-3)-cth_orig(j-3))/dinc
+       astm3znum(j)=0.5*(sth(j-3)-sth_orig(j-3))/dinc
+       endif
+
+      enddo
+
+      do i=1,nca
+        write (*,'(2i5,a2,6f10.5)') 
+     &  i,1,"x",atxnum(i),atx(i),atxnum(i)/atx(i),
+     &          astxnum(i),astx(i),astxnum(i)/astx(i),
+     &  i,1,"y",atynum(i),aty(i),atynum(i)/aty(i),
+     &          astynum(i),asty(i),astynum(i)/asty(i),
+     &  i,1,"z",atznum(i),atz(i),atznum(i)/atz(i),
+     &          astznum(i),astz(i),astznum(i)/astz(i),
+     &  i,2,"x",atmxnum(i),atmx(i),atmxnum(i)/atmx(i),
+     &          astmxnum(i),astmx(i),astmxnum(i)/astmx(i),
+     &  i,2,"y",atmynum(i),atmy(i),atmynum(i)/atmy(i),
+     &          astmynum(i),astmy(i),astmynum(i)/astmy(i),
+     &  i,2,"z",atmznum(i),atmz(i),atmznum(i)/atmz(i),
+     &          astmznum(i),astmz(i),astmznum(i)/astmz(i),
+     &  i,3,"x",atmmxnum(i),atmmx(i),atmmxnum(i)/atmmx(i),
+     &          astmmxnum(i),astmmx(i),astmmxnum(i)/astmmx(i),
+     &  i,3,"y",atmmynum(i),atmmy(i),atmmynum(i)/atmmy(i),
+     &          astmmynum(i),astmmy(i),astmmynum(i)/astmmy(i),
+     &  i,3,"z",atmmznum(i),atmmz(i),atmmznum(i)/atmmz(i),
+     &          astmmznum(i),astmmz(i),astmmznum(i)/astmmz(i),
+     &  i,4,"x",atm3xnum(i),atm3x(i),atm3xnum(i)/atm3x(i),
+     &          astm3xnum(i),astm3x(i),astm3xnum(i)/astm3x(i),
+     &  i,4,"y",atm3ynum(i),atm3y(i),atm3ynum(i)/atm3y(i),
+     &          astm3ynum(i),astm3y(i),astm3ynum(i)/astm3y(i),
+     &  i,4,"z",atm3znum(i),atm3z(i),atm3znum(i)/atm3z(i),
+     &          astm3znum(i),astm3z(i),astm3znum(i)/astm3z(i),
+     &  i,0," ",cth_orig(i),sth_orig(i)
+      enddo
+
+
+      gdfab=0
+      dinc=0.001
+
+      do j=1,nca
+
+       bx(j)=bx(j)+dinc
+       call angvectors(nca)
+       call sheetforce(nca,wshet)
+       vbeta1=vbeta*beta_inc
+       bx(j)=bx(j)-2*dinc
+       call angvectors(nca)
+       call sheetforce(nca,wshet)
+       vbeta2=vbeta*beta_inc
+       gdfab(1,j)=(vbeta2-vbeta1)/dinc/2
+       bx(j)=bx(j)+dinc
+
+       by(j)=by(j)+dinc
+       call angvectors(nca)
+       call sheetforce(nca,wshet)
+       vbeta1=vbeta*beta_inc
+       by(j)=by(j)-2*dinc
+       call angvectors(nca)
+       call sheetforce(nca,wshet)
+       vbeta2=vbeta*beta_inc
+       gdfab(2,j)=(vbeta2-vbeta1)/dinc/2
+       by(j)=by(j)+dinc
+
+       bz(j)=bz(j)+dinc
+       call angvectors(nca)
+       call sheetforce(nca,wshet)
+       vbeta1=vbeta*beta_inc
+       bz(j)=bz(j)-2*dinc
+       call angvectors(nca)
+       call sheetforce(nca,wshet)
+       vbeta2=vbeta*beta_inc
+       gdfab(3,j)=(vbeta2-vbeta1)/dinc/2
+       bz(j)=bz(j)+dinc
+
+
+      enddo
+
+
+      call angvectors(nca)
+      call sheetforce(nca,wshet)
+      do j=1,nca
+         shetfx(j)=shetfx(j)*beta_inc
+         shetfy(j)=shetfy(j)*beta_inc
+         shetfz(j)=shetfz(j)*beta_inc
+      enddo
+
+
+      write(*,*) 'xyz analytical and numerical gradient'
+      do j=1,nca
+        write(*,'(5x,i5,10x,6f10.5)') j,-shetfx(j),-shetfy(j),-shetfz(j)
+     &                   ,(-gdfab(i,j),i=1,3)
+      enddo
+
+      do j=1,nca
+        write(*,'(5x,i5,10x,3f10.2)') j,shetfx(j)/gdfab(1,j),
+     &                                  shetfy(j)/gdfab(2,j),
+     &                                  shetfz(j)/gdfab(3,j)
+      enddo
+
+      stop
+#endif
+      
+      return
+      end
+C-------------------------------------------------------------------------------
+      subroutine angvectors(nca)
+c      implicit real*4(a-h,o-z)
+      implicit none
+      integer nca
+      integer maxca
+      parameter(maxca=800)
+      real*8   pai,zero
+      parameter(PAI=3.14159265358979323846D0,zero=0.0d0)
+
+      real*8   bx(maxca),by(maxca),bz(maxca)
+      real*8   dis(maxca,maxca)
+      real*8   apx(maxca),apy(maxca),apz(maxca)
+      real*8   apmx(maxca),apmy(maxca),apmz(maxca)
+      real*8   apmmx(maxca),apmmy(maxca),apmmz(maxca)
+      real*8   apm3x(maxca),apm3y(maxca),apm3z(maxca)
+      real*8   atx(maxca),aty(maxca),atz(maxca)
+      real*8   atmx(maxca),atmy(maxca),atmz(maxca)
+      real*8   atmmx(maxca),atmmy(maxca),atmmz(maxca)
+      real*8   atm3x(maxca),atm3y(maxca),atm3z(maxca)
+      real*8   astx(maxca),asty(maxca),astz(maxca)
+      real*8   astmx(maxca),astmy(maxca),astmz(maxca)
+      real*8   astmmx(maxca),astmmy(maxca),astmmz(maxca)
+      real*8   astm3x(maxca),astm3y(maxca),astm3z(maxca)
+      real*8   sth(maxca)
+      real*8   cph(maxca),cth(maxca)
+      real*8   ulcos(maxca)
+      real*8   p,c
+      integer  i, ip, ipp, ip3, j
+      real*8   rx(maxca, maxca), ry(maxca, maxca), rz(maxca, maxca)
+      real*8   rix, riy, riz, ripx, ripy, ripz, rippx, rippy, rippz
+      real*8   gix, giy, giz, gipx, gipy, gipz, gippx, gippy, gippz
+      real*8   cix, ciy, ciz, cipx, cipy, cipz
+      real*8   gpcrp_x, gpcrp_y, gpcrp_z, d_gpcrp, gpcrp__g
+      real*8   d10, d11, d12, d13, d20, d21, d22, d23, d24
+      real*8   d30, d31, d32, d33, d34, d35, d40, d41, d42, d43
+      real*8   d_gcr, d_gcr3, d_gmcrim,d_gmcrim3,dgmmcrimm,d_gmmcrimm3
+      real*8   dg, dg3, dg30, dgm, dgm3, dgmm, dgmm3, dgp, dri
+      real*8   dri3, drim, drim3, drimm, drip, dripp, g3gmm, g3rim
+      real*8   g3x, g3y, g3z, d_gmmcrimm, g3rim_,gcr__gm
+      real*8   gcr_x,gcr_y,gcr_z,ggm,ggp,gmcrim__gmm
+      real*8   gmcrim_x,gmcrim_y,gmcrim_z,gmmcrimm__gmmm
+      real*8   gmmcrimm_x,gmmcrimm_y,gmmcrimm_z,gmmgm,gmmr
+      real*8   gmmx,gmmy,gmmz,gmrp,gmx,gmy,gmz,gpx,gpy,gpz
+      real*8   grpp,gx,gy,gz
+      real*8   rim3x,rim3y,rim3z,rimmx,rimmy,rimmz,rimx,rimy,rimz
+      real*8   sd10,sd11,sd20,sd21,sd22,sd30,sd31,sd32,sd40,sd41
+      integer inb,nmax,iselect
+
+      common /sheca/   bx,by,bz
+      common /difvec/  rx, ry, rz
+      common /ulang/    ulcos
+      common /phys1/   inb,nmax,iselect
+      common /phys4/   p,c
+      common /kyori2/  dis
+      common /angvp/ apx,apy,apz,apmx,apmy,apmz,apmmx,apmmy,
+     &     apmmz,apm3x,apm3y,apm3z
+      common /angvt/ atx,aty,atz,atmx,atmy,atmz,atmmx,atmmy,
+     &     atmmz,atm3x,atm3y,atm3z
+      common /coscos/   cph,cth
+      common /angvt2/ astx,asty,astz,astmx,astmy,astmz,astmmx,astmmy,
+     &     astmmz,astm3x,astm3y,astm3z
+      common /sinsin/   sth
+C-------------------------------------------------------------------------------
+c      write(*,*) 'inside angvectors'
+C     initialize
+      p=0.1d0
+      c=1.0d0
+      inb=nca
+      cph=zero; cth=zero; sth=zero
+      apx=zero;apy=zero;apz=zero;apmx=zero;apmy=zero;apmz=zero
+      apmmx=zero;apmmy=zero;apmmz=zero;apm3x=zero;apm3y=zero;apm3z=zero
+      atx=zero;aty=zero;atz=zero;atmx=zero;atmy=zero;atmz=zero
+      atmmx=zero;atmmy=zero;atmmz=zero;atm3x=zero;atm3y=zero;atm3z=zero
+      astx=zero;asty=zero;astz=zero;astmx=zero;astmy=zero;astmz=zero
+      astmmx=zero;astmmy=zero;astmmz=zero;astm3x=zero;astm3y=zero
+      astm3z=zero
+C     end of initialize
+C     r[x,y,z] calc and distance calculation
+      rx=zero;ry=zero;rz=zero
+
+      do i=1,inb
+         do j=1,inb
+            rx(i,j)=bx(j)-bx(i)
+            ry(i,j)=by(j)-by(i)
+            rz(i,j)=bz(j)-bz(i)
+            dis(i,j)=sqrt(rx(i,j)**2+ry(i,j)**2+rz(i,j)**2)
+c            write(*,*) 'rx(i,j):',i,j,rx(i,j),bx(j),bx(i)
+c            write(*,*) 'ry(i,j):',i,j,ry(i,j),by(j),by(i)
+c            write(*,*) 'rz(i,j):',i,j,rz(i,j),bz(j),bz(i)
+c            write(*,*) 'dis(i,j):',i,j,dis(i,j)
+         enddo
+      enddo
+c     end of r[x,y,z] calc
+C     cos calc
+      do i=1,inb-2
+         ip=i+1
+         ipp=i+2
+
+         if(dis(i,ip).ge.1.0e-8.and.dis(ip,ipp).ge.1.0e-8) then
+            ulcos(i)=rx(i,ip)*rx(ip,ipp)+ry(i,ip)*ry(ip,ipp)
+     $           +rz(i,ip)*rz(ip,ipp)
+            ulcos(i)=ulcos(i)/(dis(i,ip)*dis(ip,ipp))
+         endif
+      enddo
+c     end of virtual bond angle
+c      write(*,*) 'inside angvectors1'
+crc       do i=1,inb-3
+      do i=1,inb
+         ip=i+1
+         ipp=i+2
+         ip3=i+3
+         rix=bx(ip)-bx(i)
+         riy=by(ip)-by(i)
+         riz=bz(ip)-bz(i)
+         ripx=bx(ipp)-bx(ip)
+         ripy=by(ipp)-by(ip)
+         ripz=bz(ipp)-bz(ip)
+         rippx=bx(ip3)-bx(ipp)
+         rippy=by(ip3)-by(ipp)
+         rippz=bz(ip3)-bz(ipp)
+
+         gx=riy*ripz-riz*ripy
+         gy=riz*ripx-rix*ripz
+         gz=rix*ripy-riy*ripx
+         gpx=ripy*rippz-ripz*rippy
+         gpy=ripz*rippx-ripx*rippz
+         gpz=ripx*rippy-ripy*rippx
+         gpcrp_x=gpy*ripz-gpz*ripy
+         gpcrp_y=gpz*ripx-gpx*ripz
+         gpcrp_z=gpx*ripy-gpy*ripx
+         d_gpcrp=sqrt(gpcrp_x**2+gpcrp_y**2+gpcrp_z**2)
+         gpcrp__g=gx*gpy*ripz+gpx*ripy*gz+ripx*gpz*gy
+     &        -gz*gpy*ripx-gpz*ripy*gx-ripz*gpx*gy
+
+         if(i.ge.2) then
+            rimx=bx(i)-bx(i-1)
+            rimy=by(i)-by(i-1)
+            rimz=bz(i)-bz(i-1)
+            gmx=rimy*riz-rimz*riy
+            gmy=rimz*rix-rimx*riz
+            gmz=rimx*riy-rimy*rix
+            dgm=sqrt(gmx**2+gmy**2+gmz**2)
+            dgm3=dgm**3
+            ggm=gmx*gx+gmy*gy+gmz*gz
+            gmrp=gmx*ripx+gmy*ripy+gmz*ripz
+            drim=dis(i-1,i)
+            drim3=drim**3
+            gcr_x=gy*riz-gz*riy
+            gcr_y=gz*rix-gx*riz
+            gcr_z=gx*riy-gy*rix
+            d_gcr=sqrt(gcr_x**2+gcr_y**2+gcr_z**2)
+            d_gcr3=d_gcr**3
+            gcr__gm=gmx*gy*riz+gx*riy*gmz+rix*gz*gmy
+     &           -gmz*gy*rix-gz*riy*gmx-riz*gx*gmy
+         endif
+c         write(*,*) 'inside angvectors2'
+         if(i.ge.3) then
+            rimmx=bx(i-1)-bx(i-2)
+            rimmy=by(i-1)-by(i-2)
+            rimmz=bz(i-1)-bz(i-2)
+            drimm=dis(i-2,i-1)
+            gmmx=rimmy*rimz-rimmz*rimy
+            gmmy=rimmz*rimx-rimmx*rimz
+            gmmz=rimmx*rimy-rimmy*rimx
+            dgmm=sqrt(gmmx**2+gmmy**2+gmmz**2)
+            dgmm3=dgmm**3
+            gmmgm=gmmx*gmx+gmmy*gmy+gmmz*gmz
+            gmmr=gmmx*rix+gmmy*riy+gmmz*riz
+            gmcrim_x=gmy*rimz-gmz*rimy
+            gmcrim_y=gmz*rimx-gmx*rimz
+            gmcrim_z=gmx*rimy-gmy*rimx
+            d_gmcrim=sqrt(gmcrim_x**2+gmcrim_y**2+gmcrim_z**2)
+            d_gmcrim3=d_gmcrim**3
+            gmcrim__gmm=gmmx*gmy*rimz+gmx*rimy*gmmz+rimx*gmz*gmmy
+     &           -gmmz*gmy*rimx-gmz*rimy*gmmx-rimz*gmx*gmmy
+         endif
+         
+         if(i.ge.4) then
+            rim3x=bx(i-2)-bx(i-3)
+            rim3y=by(i-2)-by(i-3)
+            rim3z=bz(i-2)-bz(i-3)
+            g3x=rim3y*rimmz-rim3z*rimmy
+            g3y=rim3z*rimmx-rim3x*rimmz
+            g3z=rim3x*rimmy-rim3y*rimmx
+            dg30=sqrt(g3x**2+g3y**2+g3z**2)
+            g3gmm=g3x*gmmx+g3y*gmmy+g3z*gmmz
+            g3rim_=g3x*rimx+g3y*rimy+g3z*rimz
+cc**********************************************************************
+            gmmcrimm_x=gmmy*rimmz-gmmz*rimmy
+            gmmcrimm_y=gmmz*rimmx-gmmx*rimmz
+            gmmcrimm_z=gmmx*rimmy-gmmy*rimmx
+            d_gmmcrimm=sqrt(gmmcrimm_x**2+gmmcrimm_y**2+gmmcrimm_z**2)
+            d_gmmcrimm3=d_gmmcrimm**3
+            gmmcrimm__gmmm=g3x*gmmy*rimmz+gmmx*rimmy*g3z+rimmx*gmmz*g3y
+     &           -g3z*gmmy*rimmx-gmmz*rimmy*g3x-rimmz*gmmx*g3y
+         endif
+         
+         dri=dis(i,i+1)
+         drip=dis(i+1,i+2)
+         dripp=dis(i+2,i+3)
+         dri3=dri**3
+         dg=sqrt(gx**2+gy**2+gz**2)
+         dgp=sqrt(gpx**2+gpy**2+gpz**2)
+         dg3=dg**3
+         
+         ggp=gx*gpx+gy*gpy+gz*gpz
+         grpp=gx*rippx+gy*rippy+gz*rippz
+         
+         if(dg.gt.0.0D0.and.dripp.gt.0.0D0.and.dgp.gt.0.0D0
+     &        .and.d_gpcrp.gt.0.0D0) then
+            cph(i)=grpp/dg/dripp
+            cth(i)=ggp/dg/dgp
+            sth(i)=gpcrp__g/d_gpcrp/dg
+         else
+c     
+            cph(i)=1.0D0
+            cth(i)=1.0D0
+            sth(i)=0.0D0
+         endif
+
+c         write(*,*) 'inside angvectors3'
+
+         if(dgp.gt.0.0D0.and.dg3.gt.0.0D0
+     &        .and.dripp.gt.0.0D0.and.d_gpcrp.gt.0.0D0) then
+            d10=1.0D0/(dg*dgp)
+            d11=ggp/(dg3*dgp)
+            d12=1.0D0/(dg*dripp)
+            d13=grpp/(dg3*dripp)
+            sd10=1.0D0/(d_gpcrp*dg)
+            sd11=gpcrp__g/(d_gpcrp*dg3)
+         else
+            d10=0.0D0
+            d11=0.0D0
+            d12=0.0D0
+            d13=0.0D0
+            sd10=0.0D0
+            sd11=0.0D0
+         endif
+         
+         atx(i)=(ripz*gpy-ripy*gpz)*d10
+     &        -(gy*ripz-gz*ripy)*d11
+         aty(i)=(ripx*gpz-ripz*gpx)*d10
+     &        -(gz*ripx-gx*ripz)*d11
+         atz(i)=(ripy*gpx-ripx*gpy)*d10
+     &        -(gx*ripy-gy*ripx)*d11
+         astx(i)=sd10*(-gpx*ripy**2+ripx*gpz*ripz
+     &        +ripy*gpy*ripx-gpx*ripz**2)
+     &        -sd11*(gy*ripz-gz*ripy)
+         asty(i)=sd10*(-gpy*ripz**2+gpx*ripy*ripx
+     &        -gpy*ripx**2+gpz*ripy*ripz)
+     &        -sd11*(-gx*ripz+gz*ripx)
+         astz(i)=sd10*(ripy*gpy*ripz-gpz*ripx**2
+     &        -gpz*ripy**2+ripz*gpx*ripx)
+     &        -sd11*(gx*ripy-gy*ripx)
+         apx(i)=(ripz*rippy-ripy*rippz)*d12
+     &        -(gy*ripz-gz*ripy)*d13
+         apy(i)=(ripx*rippz-ripz*rippx)*d12
+     &        -(gz*ripx-gx*ripz)*d13
+         apz(i)=(ripy*rippx-ripx*rippy)*d12
+     &        -(gx*ripy-gy*ripx)*d13
+         
+         if(i.ge.2) then
+            cix=bx(ip)-bx(i-1)
+            ciy=by(ip)-by(i-1)
+            ciz=bz(ip)-bz(i-1)
+            cipx=bx(ipp)-bx(i)
+            cipy=by(ipp)-by(i)
+            cipz=bz(ipp)-bz(i)
+            ripx=bx(ipp)-bx(ip)
+            ripy=by(ipp)-by(ip)
+            ripz=bz(ipp)-bz(ip)
+            if(dgm3.gt.0.0D0.and.dg3.gt.0.0D0.and.drip.gt.0.0D0
+     &           .and.d_gcr3.gt.0.0D0) then
+               d20=1.0D0/(dg*dgm)
+               d21=ggm/(dgm3*dg)
+               d22=ggm/(dgm*dg3)
+               d23=1.0D0/(dgm*drip)
+               d24=gmrp/(dgm3*drip)
+               sd20=1.0D0/(d_gcr*dgm)
+               sd21=gcr__gm/(d_gcr3*dgm)
+               sd22=gcr__gm/(d_gcr*dgm3)
+            else
+               d20=0.0D0
+               d21=0.0D0
+               d22=0.0D0
+               d23=0.0D0
+               d24=0.0D0
+               sd20=0.0D0
+               sd21=0.0D0
+               sd22=0.0D0
+            endif
+            atmx(i)=(ciy*gz-ciz*gy-ripy*gmz+ripz*gmy)*d20
+     &           -(ciy*gmz-ciz*gmy)*d21
+     &           +(ripy*gz-ripz*gy)*d22
+            atmy(i)=(ciz*gx-cix*gz-ripz*gmx+ripx*gmz)*d20
+     &           -(ciz*gmx-cix*gmz)*d21
+     &           +(ripz*gx-ripx*gz)*d22
+            atmz(i)=(cix*gy-ciy*gx-ripx*gmy+ripy*gmx)*d20
+     &           -(cix*gmy-ciy*gmx)*d21
+     &           +(ripx*gy-ripy*gx)*d22
+cc**********************************************************************
+            astmx(i)=sd20*(gmx*ripz*riz+gx*riy*ciy-gz*gmy
+     &           -rix*ripy*gmy-rix*gz*ciz-ciy*gy*rix-gmz*ripz*rix
+     &           +gmz*gy+ripy*riy*gmx+riz*gx*ciz)
+     &           -sd21*(gcr_x*(ripz*riz+ripy*riy)+gcr_y*(-ripy*rix-gz)
+     &           +gcr_z*(-ripz*rix+gy))
+     &           -sd22*(-gmy*ciz+gmz*ciy)
+            
+            astmy(i)=sd20*(ciz*gy*riz-ripz*riy*gmz-gx*gmz-gx*riy*cix
+     &           +rix*ripx*gmy+cix*gy*rix-ripx*riy*gmx+gz*gmx-gz*riy*ciz
+     &           +riz*ripz*gmy)
+     &           -sd21*(gcr_x*(-ripx*riy+gz)+gcr_y*(ripx*rix+ripz*riz)
+     &           -gcr_z*(ripz*riy+gx))
+     &           -sd22*(gmx*ciz-gmz*cix)
+            
+            astmz(i)=sd20*(-ciy*gy*riz-gmx*ripx*riz-gmx*gy+ripy*riy*gmz
+     &           +rix*gz*cix+gmz*ripx*rix+gz*riy*ciy+gx*gmy-riz*ripy*gmy
+     &           -riz*gx*cix)
+     &           -sd21*(gcr_x*(-ripx*riz-gy)+gcr_y*(-ripy*riz+gx)
+     &           +gcr_z*(ripy*riy+ripx*rix))
+     &           -sd22*(-gmx*ciy+gmy*cix)
+cc**********************************************************************
+            apmx(i)=(ciy*ripz-ripy*ciz)*d23
+     &           -(ciy*gmz-ciz*gmy)*d24
+            apmy(i)=(ciz*ripx-ripz*cix)*d23
+     &           -(ciz*gmx-cix*gmz)*d24
+            apmz(i)=(cix*ripy-ripx*ciy)*d23
+     &           -(cix*gmy-ciy*gmx)*d24
+         endif
+         
+         if(i.ge.3) then
+            if(dgm3.gt.0.0D0.and.dgmm3.gt.0.0D0.and.dri3.gt.0.0D0
+     &           .and.d_gmcrim3.gt.0.0D0) then
+               d30=1.0D0/(dgm*dgmm)
+               d31=gmmgm/(dgm3*dgmm)
+               d32=gmmgm/(dgm*dgmm3)
+               d33=1.0D0/(dgmm*dri)
+               d34=gmmr/(dgmm3*dri)
+               d35=gmmr/(dgmm*dri3)
+               sd30=1.0D0/(d_gmcrim*dgmm)
+               sd31=gmcrim__gmm/(d_gmcrim3*dgmm)
+               sd32=gmcrim__gmm/(d_gmcrim*dgmm3)
+            else
+               d30=0.0D0
+               d31=0.0D0
+               d32=0.0D0
+               d33=0.0D0
+               d34=0.0D0
+               d35=0.0D0
+               sd30=0.0D0
+               sd31=0.0D0
+               sd32=0.0D0
+            endif
+
+c            write(*,*) 'inside angvectors4'
+
+cc**********************************************************************
+            atmmx(i)=(ciy*gmmz-ciz*gmmy-rimmy*gmz+rimmz*gmy)*d30
+     &           -(ciy*gmz-ciz*gmy)*d31
+     &           -(gmmy*rimmz-gmmz*rimmy)*d32
+            atmmy(i)=(ciz*gmmx-cix*gmmz-rimmz*gmx+rimmx*gmz)*d30
+     &           -(ciz*gmx-cix*gmz)*d31
+     &           -(gmmz*rimmx-gmmx*rimmz)*d32
+            atmmz(i)=(cix*gmmy-ciy*gmmx-rimmx*gmy+rimmy*gmx)*d30
+     &           -(cix*gmy-ciy*gmx)*d31
+     &           -(gmmx*rimmy-gmmy*rimmx)*d32
+cc**********************************************************************
+            astmmx(i)=sd30*(-gmmx*ciz*rimz-gmx*rimy*rimmy
+     &           +gmz*gmmy+rimx*ciy*gmmy+rimx*gmz*rimmz
+     &           +rimmy*gmy*rimx+gmmz*ciz*rimx-gmmz*gmy
+     &           -ciy*rimy*gmmx-rimz*gmx*rimmz)
+     &           -sd31*(gmcrim_x*(-ciz*rimz-ciy*rimy)
+     &           +gmcrim_y*(ciy*rimx+gmz)+gmcrim_z*(ciz*rimx-gmy))
+     &           -sd32*(gmmy*rimmz-rimmy*gmmz)
+            
+            astmmy(i)=sd30*(-rimmz*gmy*rimz+ciz*rimy*gmmz
+     &           +gmx*gmmz+gmx*rimy*rimmx-rimx*cix*gmmy
+     &           -rimmx*gmy*rimx+cix*rimy*gmmx-gmz*gmmx
+     &           +gmz*rimy*rimmz-rimz*ciz*gmmy)
+     &           -sd31*(gmcrim_x*(cix*rimy-gmz)
+     &           +gmcrim_y*(-cix*rimx-ciz*rimz)+gmcrim_z*(ciz*rimy+gmx))
+     &           -sd32*(-gmmx*rimmz+rimmx*gmmz)
+            
+            astmmz(i)=sd30*(rimmy*gmy*rimz+gmmx*cix*rimz
+     &           +gmmx*gmy-ciy*rimy*gmmz-rimx*gmz*rimmx
+     &           -gmmz*cix*rimx-gmz*rimy*rimmy-gmx*gmmy
+     &           +rimz*ciy*gmmy+rimz*gmx*rimmx)
+     &           -sd31*(gmcrim_x*(cix*rimz+gmy)
+     &           +gmcrim_y*(ciy*rimz-gmx)+gmcrim_z*(-ciy*rimy-cix*rimx))
+     &           -sd32*(gmmx*rimmy-rimmx*gmmy)
+c**********************************************************************
+            apmmx(i)=(riy*rimmz-riz*rimmy-gmmx)*d33
+     &           -(gmmy*rimmz-gmmz*rimmy)*d34
+     &           +rix*d35
+            apmmy(i)=(riz*rimmx-rix*rimmz-gmmy)*d33
+     &           -(gmmz*rimmx-gmmx*rimmz)*d34
+     &           +riy*d35
+            apmmz(i)=(rix*rimmy-riy*rimmx-gmmz)*d33
+     &           -(gmmx*rimmy-gmmy*rimmx)*d34
+     &           +riz*d35
+         endif   
+         
+         if(i.ge.4) then
+            if(dg30.gt.0.0D0.and.dgmm3.gt.0.0D0
+     &           .and.drim3.gt.0.0D0
+     &           .and.d_gmmcrimm3.gt.0.0D0) then
+               d40=1.0D0/(dg30*dgmm)
+               d41=g3gmm/(dg30*dgmm3)
+               d42=1.0D0/(dg30*drim)
+               d43=g3rim_/(dg30*drim3)
+               sd40=1.0D0/(dg30*d_gmmcrimm)
+               sd41=gmmcrimm__gmmm/(d_gmmcrimm3*dg30)
+            else
+               d40=0.0D0
+               d41=0.0D0
+               d42=0.0D0
+               d43=0.0D0
+               sd40=0.0D0
+               sd41=0.0D0
+            endif
+            atm3x(i)=(g3y*rimmz-g3z*rimmy)*d40
+     &           -(gmmy*rimmz-gmmz*rimmy)*d41
+            atm3y(i)=(g3z*rimmx-g3x*rimmz)*d40
+     &           -(gmmz*rimmx-gmmx*rimmz)*d41
+            atm3z(i)=(g3x*rimmy-g3y*rimmx)*d40
+     &           -(gmmx*rimmy-gmmy*rimmx)*d41
+cc**********************************************************************
+            astm3x(i)=sd40*(g3x*rimmz**2-rimmx*rimmy*g3y
+     &           -g3z*rimmz*rimmx+rimmy**2*g3x)
+     &           -sd41*(gmmcrimm_x*(rimmz**2+rimmy**2)
+     &           -gmmcrimm_y*rimmy*rimmx-gmmcrimm_z*rimmz*rimmx)
+            
+            astm3y(i)=sd40*(-rimmz*rimmy*g3z+rimmx**2*g3y
+     &           -rimmx*rimmy*g3x+rimmz**2*g3y)
+     &           -sd41*(-gmmcrimm_x*rimmx*rimmy
+     &           +gmmcrimm_y*(rimmx**2+rimmz**2)-gmmcrimm_z*rimmz*rimmy)
+
+c     &           +gmmcrimm_y*(rimmx**2+rimmz**2)-gmmcrimm_z*rimmz*rimmx)
+            
+            astm3z(i)=sd40*(-g3x*rimmx*rimmz+rimmy**2*g3z
+     &           +g3z*rimmx**2-rimmz*rimmy*g3y)
+     &           -sd41*(-gmmcrimm_x*rimmx*rimmz-gmmcrimm_y*rimmy*rimmz
+     &           +gmmcrimm_z*(rimmy**2+rimmx**2))
+c**********************************************************************
+            apm3x(i)=g3x*d42-rimx*d43
+            apm3y(i)=g3y*d42-rimy*d43
+            apm3z(i)=g3z*d42-rimz*d43
+         endif
+      enddo
+c*******************************************************************************
+
+c      write(*,*) 'inside angvectors5'
+
+c       do i=inb-2,inb
+       do i=1,0
+         rimx=bx(i)-bx(i-1)
+         rimy=by(i)-by(i-1)
+         rimz=bz(i)-bz(i-1)
+         rimmx=bx(i-1)-bx(i-2)
+         rimmy=by(i-1)-by(i-2)
+         rimmz=bz(i-1)-bz(i-2)
+         rim3x=bx(i-2)-bx(i-3)
+         rim3y=by(i-2)-by(i-3)
+         rim3z=bz(i-2)-bz(i-3)
+         gmmx=rimmy*rimz-rimmz*rimy
+         gmmy=rimmz*rimx-rimmx*rimz
+         gmmz=rimmx*rimy-rimmy*rimx
+         g3x=rim3y*rimmz-rim3z*rimmy
+         g3y=rim3z*rimmx-rim3x*rimmz
+         g3z=rim3x*rimmy-rim3y*rimmx
+         
+         dg30=sqrt(g3x**2+g3y**2+g3z**2)
+         g3gmm=g3x*gmmx+g3y*gmmy+g3z*gmmz
+         dgmm=sqrt(gmmx**2+gmmy**2+gmmz**2)
+         dgmm3=dgmm**3
+         drim=dis(i-1,i)
+         drimm=dis(i-2,i-1)
+         drim3=drim**3
+         g3rim_=g3x*rimx+g3y*rimy+g3z*rimz
+cc**********************************************************************
+         gmmcrimm_x=gmmy*rimmz-gmmz*rimmy
+         gmmcrimm_y=gmmz*rimmx-gmmx*rimmz
+         gmmcrimm_z=gmmx*rimmy-gmmy*rimmx
+         d_gmmcrimm=sqrt(gmmcrimm_x**2+gmmcrimm_y**2+gmmcrimm_z**2)
+         d_gmmcrimm3=d_gmmcrimm**3
+         gmmcrimm__gmmm=g3x*gmmy*rimmz+gmmx*rimmy*g3z+rimmx*gmmz*g3y
+     &        -g3z*gmmy*rimmx-gmmz*rimmy*g3x-rimmz*gmmx*g3y
+         
+         if(dg30.gt.0.0D0.and.dgmm3.gt.0.0D0
+     &        .and.drim3.gt.0.0D0
+     &        .and.d_gmmcrimm3.gt.0.0D0) then
+            d40=1.0D0/(dg30*dgmm)
+            d41=g3gmm/(dg30*dgmm3)
+            d42=1.0D0/(dg30*drim)
+            d43=g3rim_/(dg30*drim3)
+            sd40=1.0D0/(dg30*d_gmmcrimm)
+            sd41=gmmcrimm__gmmm/(d_gmmcrimm3*dg30)
+         else
+            d40=0.0D0
+            d41=0.0D0
+            d42=0.0D0
+            d43=0.0D0
+            sd40=0.0D0
+            sd41=0.0D0
+         endif
+         atm3x(i)=(g3y*rimmz-g3z*rimmy)*d40
+     &        -(gmmy*rimmz-gmmz*rimmy)*d41
+         atm3y(i)=(g3z*rimmx-g3x*rimmz)*d40
+     &        -(gmmz*rimmx-gmmx*rimmz)*d41
+         atm3z(i)=(g3x*rimmy-g3y*rimmx)*d40
+     &        -(gmmx*rimmy-gmmy*rimmx)*d41
+cc**********************************************************************
+         astm3x(i)=sd40*(g3x*rimmz**2-rimmx*rimmy*g3y
+     &        -g3z*rimmz*rimmx+rimmy**2*g3x)
+     &        -sd41*(gmmcrimm_x*(rimmz**2+rimmy**2)
+     &        -gmmcrimm_y*rimmy*rimmx-gmmcrimm_z*rimmz*rimmx)
+         
+         astm3y(i)=sd40*(-rimmz*rimmy*g3z+rimmx**2*g3y
+     &        -rimmx*rimmy*g3x+rimmz**2*g3y)
+     &        -sd41*(-gmmcrimm_x*rimmx*rimmy
+     &        +gmmcrimm_y*(rimmx**2+rimmz**2)-gmmcrimm_z*rimmz*rimmx)
+         
+         astm3z(i)=sd40*(-g3x*rimmx*rimmz+rimmy**2*g3z
+     &        +g3z*rimmx**2-rimmz*rimmy*g3y)
+     &        -sd41*(-gmmcrimm_x*rimmx*rimmz-gmmcrimm_y*rimmy*rimmz
+     &        +gmmcrimm_z*(rimmy**2+rimmx**2))
+cc**********************************************************************
+         apm3x(i)=g3x*d42-rimx*d43
+         apm3y(i)=g3y*d42-rimy*d43
+         apm3z(i)=g3z*d42-rimz*d43
+         
+         if(i.le.inb-1) then
+            ip=i+1
+            rix=bx(ip)-bx(i)
+            riy=by(ip)-by(i)
+            riz=bz(ip)-bz(i)
+            cix=bx(ip)-bx(i-1)
+            ciy=by(ip)-by(i-1)
+            ciz=bz(ip)-bz(i-1)
+            gmx=rimy*riz-rimz*riy
+            gmy=rimz*rix-rimx*riz
+            gmz=rimx*riy-rimy*rix
+            dgm=sqrt(gmx**2+gmy**2+gmz**2)
+            dgm3=dgm**3
+            dri=dis(i,i+1)
+            dri3=dri**3
+            gmmgm=gmmx*gmx+gmmy*gmy+gmmz+gmz
+            gmmr=gmmx*rix+gmmy*riy+gmmz*riz
+            gmcrim_x=gmy*rimz-gmz*rimy
+            gmcrim_y=gmz*rimx-gmx*rimz
+            gmcrim_z=gmx*rimy-gmy*rimx
+            d_gmcrim=sqrt(gmcrim_x**2+gmcrim_y**2+gmcrim_z**2)
+            d_gmcrim3=d_gmcrim**3
+            gmcrim__gmm=gmmx*gmy*rimz+gmx*rimy*gmmz+rimx*gmz*gmmy
+     &           -gmmz*gmy*rimx-gmz*rimy*gmmx-rimz*gmx*gmmy
+            
+            if(dgm3.gt.0.0D0.and.
+     &           dgmm3.gt.0.0D0.and.dri3.gt.0.0D0
+     &           .and.d_gmcrim3.gt.0.0D0) then
+               d30=1.0D0/(dgm*dgmm)
+               d31=gmmgm/(dgm3*dgmm)
+               d32=gmmgm/(dgm*dgmm3)
+               d33=1.0D0/(dgmm*dri)
+               d34=gmmr/(dgmm3*dri)
+               d35=gmmr/(dgmm*dri3)
+               sd30=1.0D0/(d_gmcrim*dgmm)
+               sd31=gmcrim__gmm/(d_gmcrim3*dgmm)
+               sd32=gmcrim__gmm/(d_gmcrim*dgmm3)
+               
+            else
+               d30=0.0D0
+               d31=0.0D0
+               d32=0.0D0
+               d33=0.0D0
+               d34=0.0D0
+               d35=0.0D0
+               sd30=0.0D0
+               sd31=0.0D0
+               sd32=0.0D0
+            endif
+cc**********************************************************************
+            atmmx(i)=(ciy*gmmz-ciz*gmmy-rimmy*gmz+rimmz*gmy)*d30
+     &           -(ciy*gmz-ciz*gmy)*d31
+     &           -(gmmy*rimmz-gmmz*rimmy)*d32
+            atmmy(i)=(ciz*gmmx-cix*gmmz-rimmz*gmx+rimmx*gmz)*d30
+     &           -(ciz*gmx-cix*gmz)*d31
+     &           -(gmmz*rimmx-gmmx*rimmz)*d32
+            atmmz(i)=(cix*gmmy-ciy*gmmx-rimmx*gmy+rimmy*gmx)*d30
+     &           -(cix*gmy-ciy*gmx)*d31
+     &           -(gmmx*rimmy-gmmy*rimmx)*d32
+cc**********************************************************************
+            astmmx(i)=sd30*(-gmmx*ciz*rimz-gmx*rimy*rimmy
+     &           +gmz*gmmy+rimx*ciy*gmmy+rimx*gmz*rimmz
+     &           +rimmy*gmy*rimx+gmmz*ciz*rimx-gmmz*gmy
+     &           -ciy*rimy*gmmx-rimz*gmx*rimmz)
+     &           -sd31*(gmcrim_x*(-ciz*rimz-ciy*rimy)
+     &           +gmcrim_y*(ciy*rimx+gmz)+gmcrim_z*(ciz*rimx-gmy))
+     &           -sd32*(gmmy*rimmz-rimmy*gmmz)
+            
+            astmmy(i)=sd30*(-rimmz*gmy*rimz+ciz*rimy*gmmz
+     &           +gmx*gmmz+gmx*rimy*rimmx-rimx*cix*gmmy
+     &           -rimmx*gmy*rimx+cix*rimy*gmmx-gmz*gmmx
+     &           +gmz*rimy*rimmz-rimz*ciz*gmmy)
+     &           -sd31*(gmcrim_x*(cix*rimy-gmz)
+     &           +gmcrim_y*(-cix*rimx-ciz*rimz)+gmcrim_z*(ciz*rimy+gmx))
+     &           -sd32*(-gmmx*rimmz+rimmx*gmmz)
+            
+            astmmz(i)=sd30*(rimmy*gmy*rimz+gmmx*cix*rimz
+     &           +gmmx*gmy-ciy*rimy*gmmz-rimx*gmz*rimmx
+     &           -gmmz*cix*rimx-gmz*rimy*rimmy-gmx*gmmy
+     &           +rimz*ciy*gmmy+rimz*gmx*rimmx)
+     &           -sd31*(gmcrim_x*(cix*rimz+gmy)
+     &           +gmcrim_y*(ciy*rimz-gmx)+gmcrim_z*(-ciy*rimy-cix*rimx))
+     &           -sd32*(gmmx*rimmy-rimmx*gmmy)
+cc**********************************************************************
+            apmmx(i)=(riy*rimmz-riz*rimmy-gmmx)*d33
+     &           -(gmmy*rimmz-gmmz*rimmy)*d34
+     &           +rix*d35
+            apmmy(i)=(riz*rimmx-rix*rimmz-gmmy)*d33
+     &           -(gmmz*rimmx-gmmx*rimmz)*d34
+     &           +riy*d35
+            apmmz(i)=(rix*rimmy-riy*rimmx-gmmz)*d33
+     &           -(gmmx*rimmy-gmmy*rimmx)*d34
+     &           +riz*d35
+         endif
+         
+c         write(*,*) 'inside angvectors6'
+
+         if(i.eq.inb-2) then
+            ipp=i+2
+            ripx=bx(ipp)-bx(ip)
+            ripy=by(ipp)-by(ip)
+            ripz=bz(ipp)-bz(ip)
+            cipx=bx(ipp)-bx(i)
+            cipy=by(ipp)-by(i)
+            cipz=bz(ipp)-bz(i)
+            gx=riy*ripz-riz*ripy
+            gy=riz*ripx-rix*ripz
+            gz=rix*ripy-riy*ripx
+            ggm=gmx*gx+gmy*gy+gmz*gz
+            gmrp=gmx*ripx+gmy*ripy+gmz*ripz
+            dg=sqrt(gx**2+gy**2+gz**2)
+            dg3=dg**3
+            drip=dis(i+1,i+2)
+            gcr_x=gy*riz-gz*riy
+            gcr_y=gz*rix-gx*riz
+            gcr_z=gx*riy-gy*rix
+            d_gcr=sqrt(gcr_x**2+gcr_y**2+gcr_z**2)
+            d_gcr3=d_gcr**3
+            gcr__gm=gmx*gy*riz+gx*riy*gmz+rix*gz*gmy
+     &           -gmz*gy*rix-gz*riy*gmx-riz*gx*gmy
+            if(dgm3.gt.0.0D0.and.
+     &           dg3.gt.0.0D0.and.drip.gt.0.0D0.and.d_gcr3.gt.0.0D0
+     &           ) then
+               d20=1.0D0/(dg*dgm)
+               d21=ggm/(dgm3*dg)
+               d22=ggm/(dgm*dg3)
+               d23=1.0D0/(dgm*drip)
+               d24=gmrp/(dgm3*drip)
+               sd20=1.0D0/(d_gcr*dgm)
+               sd21=gcr__gm/(d_gcr3*dgm)
+               sd22=gcr__gm/(d_gcr*dgm3)
+            else
+               d20=0.0D0
+               d21=0.0D0
+               d22=0.0D0
+               d23=0.0D0
+               d24=0.0D0
+               sd20=0.0D0
+               sd21=0.0D0
+               sd22=0.0D0
+            endif
+            atmx(i)=(ciy*gz-ciz*gy-ripy*gmz+ripz*gmy)*d20
+     &           -(ciy*gmz-ciz*gmy)*d21
+     &           +(ripy*gz-ripz*gy)*d22
+            atmy(i)=(ciz*gx-cix*gz-ripz*gmx+ripx*gmz)*d20
+     &           -(ciz*gmx-cix*gmz)*d21
+     &           +(ripz*gx-ripx*gz)*d22
+            atmz(i)=(cix*gy-ciy*gx-ripx*gmy+ripy*gmx)*d20
+     &           -(cix*gmy-ciy*gmx)*d21
+     &           +(ripx*gy-ripy*gx)*d22
+cc**********************************************************************
+            astmx(i)=sd20*(gmx*ripz*riz+gx*riy*ciy-gz*gmy
+     &           -rix*ripy*gmy-rix*gz*ciz-ciy*gy*rix-gmz*ripz*rix
+     &           +gmz*gy+ripy*riy*gmx+riz*gx*ciz)
+     &           -sd21*(gcr_x*(ripz*riz+ripy*riy)+gcr_y*(-ripy*rix-gz)
+     &           +gcr_z*(-ripz*rix+gy))
+     &           -sd22*(-gmy*ciz+gmz*ciy)
+            
+            astmy(i)=sd20*(ciz*gy*riz-ripz*riy*gmz-gx*gmz-gx*riy*cix
+     &           +rix*ripx*gmy+cix*gy*rix-ripx*riy*gmx+gz*gmx-gz*riy*ciz
+     &           +riz*ripz*gmy)
+     &           -sd21*(gcr_x*(-ripx*riy+gz)+gcr_y*(ripx*rix+ripz*riz)
+     &           -gcr_z*(ripz*riy+gx))
+     &           -sd22*(gmx*ciz-gmz*cix)
+            
+            astmz(i)=sd20*(-ciy*gy*riz-gmx*ripx*riz-gmx*gy+ripy*riy*gmz
+     &           +rix*gz*cix+gmz*ripx*rix+gz*riy*ciy+gx*gmy-riz*ripy*gmy
+     &           -riz*gx*cix)
+     &           -sd21*(gcr_x*(-ripx*riz-gy)+gcr_y*(-ripy*riz+gx)
+     &           +gcr_z*(ripy*riy+ripx*rix))
+     &           -sd22*(-gmx*ciy+gmy*cix)
+cc**********************************************************************
+c     
+            apmx(i)=(ciy*ripz-ripy*ciz)*d23
+     &           -(ciy*gmz-ciz*gmy)*d24
+            apmy(i)=(ciz*ripx-ripz*cix)*d23
+     &           -(ciz*gmx-cix*gmz)*d24
+            apmz(i)=(cix*ripy-ripx*ciy)*d23
+     &           -(cix*gmy-ciy*gmx)*d24
+            
+         endif
+      enddo
+
+      return
+      end
+c     END of angvectors
+c-------------------------------------------------------------------------------
+C---------------------------------------------------------------------------------
+      subroutine sheetforce(nca,wshet)
+      implicit none
+C     JYLEE 
+c     this should be matched with dfa.fcm
+      integer maxca
+      parameter(maxca=800)
+cc**********************************************************************
+      integer nca
+      integer i,k
+      integer inb,nmax,iselect
+
+c      real*8 dfaexp(15001)
+
+      real*8 vbeta,vbetp,vbetm
+      real*8 shefx(maxca,12)
+      real*8 shefy(maxca,12),shefz(maxca,12)
+      real*8 shetfx(maxca),shetfy(maxca),shetfz(maxca)
+      real*8 vbet(maxca,maxca)
+      real*8 wshet(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+
+      common /sheca/  bx,by,bz
+      common /phys1/  inb,nmax,iselect
+      common /shef/   shefx,shefy,shefz
+      common /shee/   vbeta,vbet,vbetp,vbetm
+      common /shetf/  shetfx,shetfy,shetfz
+
+      inb=nca
+      do i=1,inb
+         shetfx(i)=0.0D0
+         shetfy(i)=0.0D0
+         shetfz(i)=0.0D0
+      enddo
+
+      do k=1,12
+         do i=1,inb
+            shefx(i,k)=0.0D0
+            shefy(i,k)=0.0D0
+            shefz(i,k)=0.0D0
+         enddo
+      enddo
+
+      call sheetene(nca,wshet)
+      call sheetforce1
+
+ 887  format(a,1x,i6,3x,f12.8)
+ 888  format(a,1x,i4,1x,i4,3x,f12.8)
+ 889  format(a,1x,i4,3x,f12.8)
+      !write(2,*) 'coord : '
+      do i=1,inb
+         !write(2,887) 'bx:',i,bx(i)
+         !write(2,887) 'by:',i,by(i)
+         !write(2,887) 'bz:',i,bz(i)
+      enddo
+      !write(2,*) 'After sheetforce1'
+      do i=1,inb
+         do k=1,12
+            !write(2,888) 'shefx :',i,k,shefx(i,k)
+            !write(2,888) 'shefy :',i,k,shefy(i,k)
+            !write(2,888) 'shefz :',i,k,shefz(i,k)
+         enddo
+      enddo
+
+      call sheetforce5
+
+      !write(2,*) 'After sheetforce5'
+      do i=1,inb
+         do k=1,12
+            !write(2,888) 'shefx :',i,k,shefx(i,k)
+            !write(2,888) 'shefy :',i,k,shefy(i,k)
+            !write(2,888) 'shefz :',i,k,shefz(i,k)
+         enddo
+      enddo
+
+      call sheetforce6
+
+      !write(2,*) 'After sheetforce6'
+      do i=1,inb
+         do k=1,12
+            !write(2,888) 'shefx :',i,k,shefx(i,k)
+            !write(2,888) 'shefy :',i,k,shefy(i,k)
+            !write(2,888) 'shefz :',i,k,shefz(i,k)
+         enddo
+      enddo
+
+      call sheetforce11
+
+      !write(2,*) 'After sheetforce11'
+      do i=1,inb
+         do k=1,12
+            !write(2,888) 'shefx :',i,k,shefx(i,k)
+            !write(2,888) 'shefy :',i,k,shefy(i,k)
+            !write(2,888) 'shefz :',i,k,shefz(i,k)
+         enddo
+      enddo
+
+      call sheetforce12
+
+      !write(2,*) 'After sheetforce12'
+      do i=1,inb
+         do k=1,12
+            !write(2,888) 'shefx :',i,k,shefx(i,k)
+            !write(2,888) 'shefy :',i,k,shefy(i,k)
+            !write(2,888) 'shefz :',i,k,shefz(i,k)
+         enddo
+      enddo
+
+      do i=1,inb
+         do k=1,12
+            shetfx(i)=shetfx(i)+shefx(i,k)
+            shetfy(i)=shetfy(i)+shefy(i,k)
+            shetfz(i)=shetfz(i)+shefz(i,k)
+         enddo
+      enddo
+      !write(2,*) 'Beta Finished'
+      do i=1,inb
+         !write(2,889) 'shetfx : ',i,shetfx(i)
+         !write(2,889) 'shetfy : ',i,shetfy(i)
+         !write(2,889) 'shetfz : ',i,shetfz(i)
+      enddo      
+
+      return
+      end
+C     end sheetforce
+c-------------------------------------------------------------------------------
+      subroutine sheetene(nca,wshet)
+      implicit none
+      integer maxca
+      parameter(maxca=800)
+cc******************************************************************************
+
+c      real*8 dfaexp(15001)
+      real*8 dtmp1, dtmp2, dtmp3
+
+      real*8 vbet(maxca,maxca)
+      real*8 vbetap(maxca,maxca),vbetam(maxca,maxca)
+      real*8 vbetap1(maxca,maxca),vbetam1(maxca,maxca)
+      real*8 vbetap2(maxca,maxca),vbetam2(maxca,maxca)
+      real*8 pin1(maxca,maxca),pin2(maxca,maxca)
+      real*8 pin3(maxca,maxca),pin4(maxca,maxca)
+      real*8 pina1(maxca,maxca),pina2(maxca,maxca)
+      real*8 pina3(maxca,maxca),pina4(maxca,maxca)
+      real*8 cph(maxca),cth(maxca)
+      real*8 rx(maxca,maxca)
+      real*8 ry(maxca,maxca),rz(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+      real*8 dis(maxca,maxca)
+      real*8 ulcos(maxca)
+cc**********************************************************************
+      real*8 astx(maxca),asty(maxca),astz(maxca)
+      real*8 astmx(maxca),astmy(maxca),astmz(maxca)
+      real*8 astmmx(maxca),astmmy(maxca),astmmz(maxca)
+      real*8 astm3x(maxca),astm3y(maxca),astm3z(maxca)
+      real*8 sth(maxca)
+      real*8 wshet(maxca,maxca)
+      real*8 dp45, dm45, w_beta
+      real*8 c00, s00, ulnex, dnex, dca,dlhb,ulhb,dshe,dldhb,uldhb
+      integer nca
+      integer i,ip,ipp,j,jp,jpp,inb,nmax,iselect
+      real*8 uum, uup
+      real*8 vbeta,vbetp,vbetm,y,y1,y2,yshe1,yshe2,yy1,yy2
+
+      common /sheca/    bx,by,bz
+      common /phys1/    inb,nmax,iselect
+      common /kyori2/   dis
+      common /difvec/   rx,ry,rz
+      common /coscos/   cph,cth
+      common /sheparm/  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     &     c00,s00,ulnex,dnex
+      common /sheconst/ dp45,dm45,w_beta
+      common /she/     vbetap,vbetam,vbetap1,vbetap2,vbetam1,vbetam2
+      common /shepin/  pin1,pin2,pin3,pin4,pina1,pina2,pina3,pina4
+      common /shee/    vbeta,vbet,vbetp,vbetm
+      common /ulang/    ulcos
+cc**********************************************************************
+      common /angvt2/ astx,asty,astz,astmx,astmy,astmz,astmmx,astmmy,
+     &     astmmz,astm3x,astm3y,astm3z
+      common /sinsin/   sth
+      
+      real*8 r_pair_mat(maxca,maxca)
+ci      integer istrand(maxca,maxca)
+ci      integer istrand_p(maxca,maxca),istrand_m(maxca,maxca)
+ci      common  /shetest/ istrand,istrand_p,istrand_m
+      common /beta_p/ r_pair_mat
+C-------------------------------------------------------------------------------
+      r_pair_mat = 0.0d0
+      do i=1,inb
+         do j=1,inb
+            r_pair_mat(i,j)=wshet(i,j)
+c            write(*,*) 'r_pair_mat :',i,j,r_pair_mat(i,j)
+         enddo
+      enddo
+c      stop
+c      
+      vbeta=0.0D0
+      vbetp=0.0D0
+      vbetm=0.0D0
+
+      do i=1,inb-7
+         do j=i+4,inb-3
+            ip=i+1
+            ipp=i+2
+            jp=j+1
+            jpp=j+2
+cc**********************************************************************
+            y1=(cth(i)*c00+sth(i)*s00-1.0D0)**2
+     &           +(cth(j)*c00+sth(j)*s00-1.0D0)**2
+            y1=-0.5d0*y1/dca
+            y2=(ulcos(i)-ulnex)**2+(ulcos(ip)-ulnex)**2
+     &           +(ulcos(j)-ulnex)**2+(ulcos(jp)-ulnex)**2
+            y2=-0.5d0*y2/dnex
+
+cdebug            y2=0
+
+            y=y1+y2
+      
+ci           if(y.ge.-4) then
+ci              istrand(i,j)=1
+ci           else
+ci              istrand(i,j)=0
+ci           endif
+
+ci           if(istrand(i,j).eq.1) then
+
+            yy1=-0.5d0*(dis(ip,jp)-ulhb)**2/dlhb
+            yy2=-0.5d0*(dis(ipp,jpp)-ulhb)**2/dlhb
+
+        
+            pin1(i,j)=(rx(ip,jp)*rx(ip,ipp)+ry(ip,jp)*ry(ip,ipp)
+     $           +rz(ip,jp)*rz(ip,ipp))/(dis(ip,jp)*dis(ip,ipp))
+            pin2(i,j)=(rx(ip,jp)*rx(jp,jpp)+ry(ip,jp)*ry(jp,jpp)
+     $           +rz(ip,jp)*rz(jp,jpp))/(dis(ip,jp)*dis(jp,jpp))
+            pin3(i,j)=(rx(ipp,jpp)*rx(ip,ipp)+ry(ipp,jpp)*ry(ip,ipp)
+     $           +rz(ipp,jpp)*rz(ip,ipp))/(dis(ipp,jpp)*dis(ip,ipp))
+            pin4(i,j)=(rx(ipp,jpp)*rx(jp,jpp)+ry(ipp,jpp)*ry(jp,jpp)
+     $           +rz(ipp,jpp)*rz(jp,jpp))/(dis(ipp,jpp)*dis(jp,jpp))
+         
+           yshe1=pin1(i,j)**2+pin2(i,j)**2
+           yshe1=-0.5d0*yshe1/dshe
+           yshe2=pin3(i,j)**2+pin4(i,j)**2
+           yshe2=-0.5d0*yshe2/dshe
+
+ci              if((yshe1+yshe2).ge.-4) then
+ci                 istrand_p(i,j)=1
+ci              else
+ci                 istrand_p(i,j)=0
+ci              endif
+
+           
+C            write(*,*) 'rx(i,j):',i,j,rx(i,j),bx(j),bx(i)
+C            write(*,*) 'ry(i,j):',i,j,ry(i,j),by(j),by(i)
+C            write(*,*) 'rz(i,j):',i,j,rz(i,j),bz(j),bz(i)
+C            write(*,*) 'dis(i,j):',i,j,dis(i,j)
+C            write(*,*) 'rx(ip,jp):',ip,jp,bx(ip),bx(jp),rx(ip,jp)
+C            write(*,*) 'rx(ip,ipp):',ip,ipp,bx(ip),bx(ipp),rx(ip,ipp)
+C            write(*,*) 'pin1:',pin1(i,j)
+C            write(*,*) 'pin2:',pin2(i,j)
+C            write(*,*) 'pin3:',pin3(i,j)
+C            write(*,*) 'pin4:',pin4(i,j)
+
+C            write(*,*) 'y:',y
+C            write(*,*) 'yy1:',yy1
+C            write(*,*) 'yy2:',yy2
+C            write(*,*) 'yshe1:',yshe1
+C            write(*,*) 'yshe2:',yshe2
+c            
+
+ci           if (istrand_p(i,j).eq.1) then          
+
+cd           yy1=0
+cd           yy2=0
+cd           yshe1=0
+cd           yshe2=0
+           dtmp1 = y+yy1+yshe1
+           dtmp2 = y+yy2+yshe2
+           dtmp3 = y+yy1+yy2+yshe1+yshe2
+
+C            write(*,*)'1', i,j,dtmp1,dtmp2,dtmp3
+C            write(*,*)'2', y,yy1,yy2
+C            write(*,*)'3', yshe1,yshe2
+
+cc           if (dtmp3.le.-35.0d0) then
+c              vbetap(i,j)=-dp45*exp(dtmp3)
+cc              vbetap(i,j)=0.0d0
+cc           else
+c              vbetap(i,j)=-dp45*dfaexp(idint(-dtmp3*1000)+1)
+              vbetap(i,j)=-dp45*exp(dtmp3)
+cc           end if
+
+cc           if (dtmp1.le.-35.0d0) then
+c              vbetap1(i,j)=-r_pair_mat(i+1,j+1)*exp(dtmp1)
+cc              vbetap1(i,j)=0.0d0
+cc           else
+c              vbetap1(i,j)=-r_pair_mat(i+1,j+1)
+c     $             *dfaexp(idint(-dtmp1*1000)+1)
+               vbetap1(i,j)=-r_pair_mat(i+1,j+1)*exp(dtmp1)
+cc           end if
+
+cc           if (dtmp2.le.-35.0d0) then
+C              vbetap2(i,j)=-r_pair_mat(i+2,j+2)*exp(dtmp2)
+cc              vbetap2(i,j)=0.0d0
+cc           else
+c              vbetap2(i,j)=-r_pair_mat(i+2,j+2)
+c     $             *dfaexp(idint(-dtmp2*1000)+1)
+              vbetap2(i,j)=-r_pair_mat(i+2,j+2)*exp(dtmp2)
+cc           end if
+           
+c           vbetap(i,j)=-dp45*exp(y+yy1+yy2+yshe1+yshe2)
+c           vbetap1(i,j)=-r_pair_mat(i+1,j+1)*exp(y+yy1+yshe1)
+c           vbetap2(i,j)=-r_pair_mat(i+2,j+2)*exp(y+yy2+yshe2)
+
+!           write(*,*) 'r_pair_mat>',i+1,j+1,r_pair_mat(i+1,j+1)
+!           write(*,*) 'r_pair_mat>',i+2,j+2,r_pair_mat(i+2,j+2)
+
+ci           elseif (istrand_p(i,j).eq.0)then
+ci            vbetap(i,j)=0
+ci            vbetap1(i,j)=0
+ci            vbetap2(i,j)=0
+ci           endif
+
+           yy1=-0.5d0*(dis(ip,jpp)-ulhb)**2/dlhb
+           yy2=-0.5d0*(dis(ipp,jp)-ulhb)**2/dlhb
+           
+           pina1(i,j)=(rx(ip,jpp)*rx(ip,ipp)+ry(ip,jpp)*ry(ip,ipp)
+     $          +rz(ip,jpp)*rz(ip,ipp))/(dis(ip,jpp)*dis(ip,ipp))
+           pina2(i,j)=(rx(ip,jpp)*rx(jp,jpp)+ry(ip,jpp)*ry(jp,jpp)
+     $          +rz(ip,jpp)*rz(jp,jpp))/(dis(ip,jpp)*dis(jp,jpp))
+           pina3(i,j)=(rx(jp,ipp)*rx(ip,ipp)+ry(jp,ipp)*ry(ip,ipp)
+     $          +rz(jp,ipp)*rz(ip,ipp))/(dis(jp,ipp)*dis(ip,ipp))
+           pina4(i,j)=(rx(jp,ipp)*rx(jp,jpp)+ry(jp,ipp)*ry(jp,jpp)
+     $          +rz(jp,ipp)*rz(jp,jpp))/(dis(jp,ipp)*dis(jp,jpp))
+           
+           yshe1=pina1(i,j)**2+pina2(i,j)**2
+           yshe1=-0.5d0*yshe1/dshe
+           yshe2=pina3(i,j)**2+pina4(i,j)**2
+           yshe2=-0.5d0*yshe2/dshe
+
+ci              if((yshe1+yshe2).ge.-4) then
+ci                 istrand_m(i,j)=1
+ci              else
+ci                 istrand_m(i,j)=0
+ci              endif
+
+
+C            write(*,*) 'pina1:',pina1(i,j)
+C            write(*,*) 'pina2:',pina2(i,j)
+C            write(*,*) 'pina3:',pina3(i,j)
+C            write(*,*) 'pina4:',pina4(i,j)
+C            write(*,*) 'yshe1:',yshe1
+C            write(*,*) 'yshe2:',yshe2
+C            write(*,*) 'dshe:',dshe
+
+ci           if (istrand_m(i,j).eq.1) then
+
+cd           yy1=0
+cd           yy2=0
+cd           yshe1=0
+cd           yshe2=0
+
+           dtmp3=y+yy1+yy2+yshe1+yshe2
+           dtmp1=y+yy1+yshe1
+           dtmp2=y+yy2+yshe2
+
+cc           if(dtmp3 .le. -35.0d0) then
+c              vbetam(i,j)=-dm45*exp(dtmp3)
+cc              vbetam(i,j)=0.0d0
+cc           else
+c              vbetam(i,j)=-dm45*dfaexp(idint(-dtmp3*1000)+1)
+              vbetam(i,j)=-dm45*exp(dtmp3)
+cc           end if
+
+cc           if(dtmp1 .le. -35.0d0) then
+c              vbetam1(i,j)=-r_pair_mat(i+1,j+2)*exp(dtmp1)
+cc               vbetam1(i,j)=0.0d0
+cc           else
+c              vbetam1(i,j)=-r_pair_mat(i+1,j+2)
+c     $             *dfaexp(idint(-dtmp1*1000)+1)
+               vbetam1(i,j)=-r_pair_mat(i+1,j+2)*exp(dtmp1)
+cc           end if
+
+cc           if(dtmp2.le.-35.0d0) then
+c              vbetam2(i,j)=-r_pair_mat(i+2,j+1)*exp(dtmp2)
+cc              vbetam2(i,j)=0.0d0
+cc           else
+c              vbetam2(i,j)=-r_pair_mat(i+2,j+1)
+c     $             *dfaexp(idint(-dtmp2*1000)+1)
+              vbetam2(i,j)=-r_pair_mat(i+2,j+1)*exp(dtmp2)
+cc           end if           
+
+ci           elseif (istrand_m(i,j).eq.0)then
+ci            vbetam(i,j)=0
+ci            vbetam1(i,j)=0
+ci            vbetam2(i,j)=0
+ci           endif
+
+
+c           vbetam(i,j)=-dm45*exp(y+yy1+yy2+yshe1+yshe2)
+c           vbetam1(i,j)=-r_pair_mat(i+1,j+2)*exp(y+yy1+yshe1)
+c           vbetam2(i,j)=-r_pair_mat(i+2,j+1)*exp(y+yy2+yshe2)
+
+!           write(*,*) 'r_pair_mat>',i+1,j+2,r_pair_mat(i+1,j+2)
+!           write(*,*) 'r_pair_mat>',i+2,j+1,r_pair_mat(i+2,j+1)
+
+           uup = vbetap(i,j)+vbetap1(i,j)+vbetap2(i,j)
+           uum = vbetam(i,j)+vbetam1(i,j)+vbetam2(i,j)
+
+c           write(*,*) 'uup,uum:', uup, uum
+
+c           uup=vbetap1(i,j)+vbetap2(i,j)
+c           uum=vbetam1(i,j)+vbetam2(i,j)
+
+           vbet(i,j)=uup+uum
+           vbetp=vbetp+uup
+           vbetm=vbetm+uum
+           vbeta=vbeta+vbet(i,j)
+
+ci         elseif(istrand(i,j).eq.0)then
+ci           vbet(i,j)=0
+ci         endif
+
+c           write(*,*) 'uup,uum:',uup,uum
+c           write(*,*) 'vbetap(i,j):',vbetap(i,j)
+c           write(*,*) 'vbetap1(i,j):',vbetap1(i,j)
+c           write(*,*) 'vbetap2(i,j):',vbetap2(i,j)
+c           write(*,*) 'vbetam(i,j):',vbetam(i,j)
+c           write(*,*) 'vbetam1(i,j):',vbetam1(i,j)
+c           write(*,*) 'vbetam2(i,j):',vbetam2(i,j)
+c           write(*,*) 'uup:',uup
+c           write(*,*) 'uum:',uum
+c           write(*,*) 'vbetp:',vbetp
+c           write(*,*) 'vbetm:',vbetm
+c           write(*,*) 'vbet(i,j):',vbet(i,j)
+c           stop
+
+        enddo
+      enddo
+
+!      do i=1,inb-7
+!         do j=i+4,inb-3
+!            write(*,*) 'I,J:', i,j
+!            write(*,*) 'vbetap(i,j):',vbetap(i,j)
+!            write(*,*) 'vbetap1(i,j):',vbetap1(i,j)
+!            write(*,*) 'vbetap2(i,j):',vbetap2(i,j)
+!            write(*,*) 'vbetam(i,j):',vbetam(i,j)
+!            write(*,*) 'vbetam1(i,j):',vbetam1(i,j)
+!            write(*,*) 'vbetam2(i,j):',vbetam2(i,j)
+!            write(*,*) 'vbet(i,j):',vbet(i,j)
+!         enddo
+!      enddo
+
+      return
+      end
+c-------------------------------------------------------------------------------
+      subroutine sheetforce1
+      implicit none
+      integer maxca
+      parameter(maxca=800)
+cc**********************************************************************
+      real*8 vbet(maxca,maxca)
+      real*8 vbetap(maxca,maxca),vbetam(maxca,maxca)
+      real*8 vbetap1(maxca,maxca),vbetam1(maxca,maxca)
+      real*8 vbetap2(maxca,maxca),vbetam2(maxca,maxca)
+      real*8 cph(maxca),cth(maxca)
+      real*8 rx(maxca,maxca)
+      real*8 ry(maxca,maxca),rz(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+      real*8 dis(maxca,maxca)
+      real*8 shefx(maxca,12)
+      real*8 shefy(maxca,12),shefz(maxca,12)
+      real*8 atx(maxca),aty(maxca),atz(maxca)
+      real*8 atmx(maxca),atmy(maxca),atmz(maxca)
+      real*8 atmmx(maxca),atmmy(maxca),atmmz(maxca)
+      real*8 atm3x(maxca),atm3y(maxca),atm3z(maxca)
+      real*8 apx(maxca),apy(maxca),apz(maxca)
+      real*8 apmx(maxca),apmy(maxca),apmz(maxca)
+      real*8 apmmx(maxca),apmmy(maxca),apmmz(maxca)
+      real*8 apm3x(maxca),apm3y(maxca),apm3z(maxca)
+      real*8 ulcos(maxca)
+      real*8 astx(maxca),asty(maxca),astz(maxca)
+      real*8 astmx(maxca),astmy(maxca),astmz(maxca)
+      real*8 astmmx(maxca),astmmy(maxca),astmmz(maxca)
+      real*8 astm3x(maxca),astm3y(maxca),astm3z(maxca)
+      real*8 sth(maxca)
+      real*8 w_beta,dp45, dm45
+      real*8 vbeta, vbetp, vbetm
+      real*8 dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      integer inb,nmax,iselect
+
+      common /phys1/     inb,nmax,iselect
+      common /kyori2/    dis
+      common /difvec/   rx,ry,rz
+      common /coscos/   cph,cth
+      common /sheparm/  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      common /sheconst/ dp45,dm45,w_beta
+      common /she/     vbetap,vbetam,vbetap1,vbetap2,vbetam1,vbetam2
+      common /angvt/ atx,aty,atz,atmx,atmy,atmz,atmmx,atmmy,
+     $     atmmz,atm3x,atm3y,atm3z
+      common /angvp/ apx,apy,apz,apmx,apmy,apmz,apmmx,apmmy,
+     $     apmmz,apm3x,apm3y,apm3z
+      common /shef/   shefx,shefy,shefz
+      common /shee/   vbeta,vbet,vbetp,vbetm
+      common /ulang/    ulcos
+c     c**********************************************************************
+      common /angvt2/ astx,asty,astz,astmx,astmy,astmz,astmmx,astmmy,
+     $     astmmz,astm3x,astm3y,astm3z
+      common /sinsin/   sth
+C--------------------------------------------------------------------------------
+c     local variables
+      integer i,j,im3,imm,im,ip,ipp,jm,jmm,jm3,jp,jpp
+      real*8  c1,v1,cc1,dmm,dmm__,fx,fy,fz,c2,v2,dmm1
+      real*8  c3,v3,cc2,cc3,dmm3,dmm3__,c4,v4,c7,v7,cc7,c8,v8,cc8
+      real*8  c9,v9,cc9,dmm9,dmm9__,c10,v10,dmm2,dmm1__,dmm2_1,dmm2_2
+      real*8  dmm7,dmm8,dmm7__,dmm8_1,dmm8_2
+C--------------------------------------------------------------------------------
+      do i=4,inb-4
+         im3=i-3
+         imm=i-2
+         im=i-1
+         c1=(cth(im3)*c00+sth(im3)*s00-1)/dca
+         v1=0.0D0
+         do j=i+1,inb-3
+            v1=v1+vbet(im3,j)
+         enddo
+         cc1=(ulcos(imm)-ulnex)/dnex
+         dmm=cc1/(dis(imm,im)*dis(im,i))
+         dmm__=cc1*ulcos(imm)/dis(im,i)**2
+         fx=rx(imm,im)*dmm-rx(im,i)*dmm__
+         fy=ry(imm,im)*dmm-ry(im,i)*dmm__
+         fz=rz(imm,im)*dmm-rz(im,i)*dmm__
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atm3x(i)*c00+astm3x(i)*s00)*c1
+         fy=fy+(atm3y(i)*c00+astm3y(i)*s00)*c1
+         fz=fz+(atm3z(i)*c00+astm3z(i)*s00)*c1
+         shefx(i,1)=fx*v1
+         shefy(i,1)=fy*v1
+         shefz(i,1)=fz*v1
+      enddo
+      
+      do i=3,inb-5
+         imm=i-2
+         im=i-1
+         ip=i+1
+         c2=(cth(imm)*c00+sth(imm)*s00-1)/dca
+         v2=0.0D0
+         do j=i+2,inb-3
+            v2=v2+vbet(imm,j)
+         enddo
+         cc1=(ulcos(imm)-ulnex)/dnex
+         cc2=(ulcos(im)-ulnex)/dnex
+         dmm1=cc1/(dis(imm,im)*dis(im,i))
+         dmm2=cc2/(dis(im,i)*dis(i,ip))
+         dmm1__=cc1*ulcos(imm)/dis(im,i)**2
+         dmm2_1=cc2*ulcos(im)/dis(im,i)**2
+         dmm2_2=cc2*ulcos(im)/dis(i,ip)**2
+cc**********************************************************************
+         fx=rx(imm,im)*dmm1-rx(im,i)*dmm1__+rx(i,ip)*dmm2-rx(im,i)*dmm2
+     $        -rx(im,i)*dmm2_1+rx(i,ip)*dmm2_2
+         fy=ry(imm,im)*dmm1-ry(im,i)*dmm1__+ry(i,ip)*dmm2-ry(im,i)*dmm2
+     $        -ry(im,i)*dmm2_1+ry(i,ip)*dmm2_2
+         fz=rz(imm,im)*dmm1-rz(im,i)*dmm1__+rz(i,ip)*dmm2-rz(im,i)*dmm2
+     $        -rz(im,i)*dmm2_1+rz(i,ip)*dmm2_2
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atmmx(i)*c00+astmmx(i)*s00)*c2
+         fy=fy+(atmmy(i)*c00+astmmy(i)*s00)*c2
+         fz=fz+(atmmz(i)*c00+astmmz(i)*s00)*c2
+         shefx(i,2)=fx*v2
+         shefy(i,2)=fy*v2
+         shefz(i,2)=fz*v2
+      enddo
+      do i=2,inb-6
+         im=i-1
+         ip=i+1
+         ipp=i+2
+         c3=(cth(im)*c00+sth(im)*s00-1)/dca
+         v3=0.0D0
+         do j=i+3,inb-3
+            v3=v3+vbet(im,j)
+         enddo
+         cc2=(ulcos(im)-ulnex)/dnex
+         cc3=(ulcos(i)-ulnex)/dnex
+         dmm2=cc2/(dis(im,i)*dis(i,ip))
+         dmm3=cc3/(dis(i,ip)*dis(ip,ipp))
+         dmm2_1=cc2*ulcos(im)/dis(im,i)**2
+         dmm2_2=cc2*ulcos(im)/dis(i,ip)**2
+         dmm3__=cc3*ulcos(i)/dis(i,ip)**2
+         fx=-rx(ip,ipp)*dmm3+rx(i,ip)*dmm2-rx(im,i)*dmm2
+     $        -rx(im,i)*dmm2_1+rx(i,ip)*dmm2_2+rx(i,ip)*dmm3__
+         fy=-ry(ip,ipp)*dmm3+ry(i,ip)*dmm2-ry(im,i)*dmm2
+     $        -ry(im,i)*dmm2_1+ry(i,ip)*dmm2_2+ry(i,ip)*dmm3__
+         fz=-rz(ip,ipp)*dmm3+rz(i,ip)*dmm2-rz(im,i)*dmm2
+     $        -rz(im,i)*dmm2_1+rz(i,ip)*dmm2_2+rz(i,ip)*dmm3__
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atmx(i)*c00+astmx(i)*s00)*c3
+         fy=fy+(atmy(i)*c00+astmy(i)*s00)*c3
+         fz=fz+(atmz(i)*c00+astmz(i)*s00)*c3
+         shefx(i,3)=fx*v3
+         shefy(i,3)=fy*v3
+         shefz(i,3)=fz*v3
+      enddo
+      do i=1,inb-7
+         ip=i+1
+         ipp=i+2
+         c4=(cth(i)*c00+sth(i)*s00-1)/dca
+         v4=0.0D0
+         do j=i+4,inb-3
+            v4=v4+vbet(i,j)
+         enddo
+         cc3=(ulcos(i)-ulnex)/dnex
+         dmm3=cc3/(dis(i,ip)*dis(ip,ipp))
+         dmm3__=cc3*ulcos(i)/dis(i,ip)**2
+         fx=-rx(ip,ipp)*dmm3+rx(i,ip)*dmm3__
+         fy=-ry(ip,ipp)*dmm3+ry(i,ip)*dmm3__
+         fz=-rz(ip,ipp)*dmm3+rz(i,ip)*dmm3__
+cd         fx=0
+cd         fy=0
+cd         fz=0  
+         fx=fx+(atx(i)*c00+astx(i)*s00)*c4
+         fy=fy+(aty(i)*c00+asty(i)*s00)*c4
+         fz=fz+(atz(i)*c00+astz(i)*s00)*c4
+         shefx(i,4)=fx*v4
+         shefy(i,4)=fy*v4
+         shefz(i,4)=fz*v4
+      enddo
+      do j=8,inb
+         jm3=j-3
+         jmm=j-2
+         jm=j-1
+         c7=(cth(jm3)*c00+sth(jm3)*s00-1)/dca
+         v7=0.0D0
+         do i=1,j-7
+            v7=v7+vbet(i,jm3)
+         enddo
+         cc7=(ulcos(jmm)-ulnex)/dnex
+         dmm=cc7/(dis(jmm,jm)*dis(jm,j))
+         dmm__=cc7*ulcos(jmm)/dis(jm,j)**2
+         fx=rx(jmm,jm)*dmm-rx(jm,j)*dmm__
+         fy=ry(jmm,jm)*dmm-ry(jm,j)*dmm__
+         fz=rz(jmm,jm)*dmm-rz(jm,j)*dmm__
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atm3x(j)*c00+astm3x(j)*s00)*c7
+         fy=fy+(atm3y(j)*c00+astm3y(j)*s00)*c7
+         fz=fz+(atm3z(j)*c00+astm3z(j)*s00)*c7
+         shefx(j,7)=fx*v7
+         shefy(j,7)=fy*v7
+         shefz(j,7)=fz*v7
+      enddo
+      do j=7,inb-1
+         jm=j-1
+         jmm=j-2
+         jp=j+1
+         c8=(cth(jmm)*c00+sth(jmm)*s00-1)/dca
+         v8=0.0D0
+         do i=1,j-6
+            v8=v8+vbet(i,jmm)
+         enddo
+         cc7=(ulcos(jmm)-ulnex)/dnex
+         cc8=(ulcos(jm)-ulnex)/dnex
+         dmm7=cc7/(dis(jmm,jm)*dis(jm,j))
+         dmm8=cc8/(dis(jm,j)*dis(j,jp))
+         dmm7__=cc7*ulcos(jmm)/dis(jm,j)**2
+         dmm8_1=cc8*ulcos(jm)/dis(jm,j)**2
+         dmm8_2=cc8*ulcos(jm)/dis(j,jp)**2
+         fx=rx(jmm,jm)*dmm7+rx(j,jp)*dmm8-rx(jm,j)*dmm8
+     $        -rx(jm,j)*dmm7__-rx(jm,j)*dmm8_1+rx(j,jp)*dmm8_2
+         fy=ry(jmm,jm)*dmm7+ry(j,jp)*dmm8-ry(jm,j)*dmm8
+     $        -ry(jm,j)*dmm7__-ry(jm,j)*dmm8_1+ry(j,jp)*dmm8_2
+         fz=rz(jmm,jm)*dmm7+rz(j,jp)*dmm8-rz(jm,j)*dmm8
+     $        -rz(jm,j)*dmm7__-rz(jm,j)*dmm8_1+rz(j,jp)*dmm8_2
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atmmx(j)*c00+astmmx(j)*s00)*c8
+         fy=fy+(atmmy(j)*c00+astmmy(j)*s00)*c8
+         fz=fz+(atmmz(j)*c00+astmmz(j)*s00)*c8
+         shefx(j,8)=fx*v8
+         shefy(j,8)=fy*v8
+         shefz(j,8)=fz*v8
+      enddo
+      
+      do j=6,inb-2
+         jm=j-1
+         jp=j+1
+         jpp=j+2
+         c9=(cth(jm)*c00+sth(jm)*s00-1)/dca
+         v9=0.0D0
+         do i=1,j-5
+            v9=v9+vbet(i,jm)
+         enddo
+         cc8=(ulcos(jm)-ulnex)/dnex
+         cc9=(ulcos(j)-ulnex)/dnex
+         dmm8=cc8/(dis(jm,j)*dis(j,jp))
+         dmm9=cc9/(dis(j,jp)*dis(jp,jpp))
+         dmm8_1=cc8*ulcos(jm)/dis(jm,j)**2
+         dmm8_2=cc8*ulcos(jm)/dis(j,jp)**2
+         dmm9__=cc9*ulcos(j)/dis(j,jp)**2
+         fx=-rx(jp,jpp)*dmm9+rx(j,jp)*dmm8-rx(jm,j)*dmm8
+     $        -rx(jm,j)*dmm8_1+rx(j,jp)*dmm8_2+rx(j,jp)*dmm9__
+         fy=-ry(jp,jpp)*dmm9+ry(j,jp)*dmm8-ry(jm,j)*dmm8
+     $        -ry(jm,j)*dmm8_1+ry(j,jp)*dmm8_2+ry(j,jp)*dmm9__
+         fz=-rz(jp,jpp)*dmm9+rz(j,jp)*dmm8-rz(jm,j)*dmm8
+     $        -rz(jm,j)*dmm8_1+rz(j,jp)*dmm8_2+rz(j,jp)*dmm9__
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atmx(j)*c00+astmx(j)*s00)*c9
+         fy=fy+(atmy(j)*c00+astmy(j)*s00)*c9
+         fz=fz+(atmz(j)*c00+astmz(j)*s00)*c9
+         shefx(j,9)=fx*v9
+         shefy(j,9)=fy*v9
+         shefz(j,9)=fz*v9
+      enddo
+      
+      do j=5,inb-3
+         jp=j+1
+         jpp=j+2
+         c10=(cth(j)*c00+sth(j)*s00-1)/dca
+         v10=0.0D0
+         do i=1,j-4
+            v10=v10+vbet(i,j)
+         enddo
+         cc9=(ulcos(j)-ulnex)/dnex
+         dmm9=cc9/(dis(j,jp)*dis(jp,jpp))
+         dmm9__=cc9*ulcos(j)/dis(j,jp)**2
+         fx=-rx(jp,jpp)*dmm9+rx(j,jp)*dmm9__
+         fy=-ry(jp,jpp)*dmm9+ry(j,jp)*dmm9__
+         fz=-rz(jp,jpp)*dmm9+rz(j,jp)*dmm9__
+cd         fx=0
+cd         fy=0
+cd         fz=0
+         fx=fx+(atx(j)*c00+astx(j)*s00)*c10
+         fy=fy+(aty(j)*c00+asty(j)*s00)*c10
+         fz=fz+(atz(j)*c00+astz(j)*s00)*c10
+         shefx(j,10)=fx*v10
+         shefy(j,10)=fy*v10
+         shefz(j,10)=fz*v10
+      enddo
+      
+      return
+      end
+c----------------------------------------------------------------------------
+      subroutine sheetforce5
+      implicit none
+      integer maxca
+      parameter(maxca=800)
+cc**********************************************************************
+      real*8 vbetap(maxca,maxca),vbetam(maxca,maxca)
+      real*8 vbetap1(maxca,maxca),vbetam1(maxca,maxca)
+      real*8 vbetap2(maxca,maxca),vbetam2(maxca,maxca)
+      real*8 pin1(maxca,maxca),pin2(maxca,maxca)
+      real*8 pin3(maxca,maxca),pin4(maxca,maxca)
+      real*8 pina1(maxca,maxca),pina2(maxca,maxca)
+      real*8 pina3(maxca,maxca),pina4(maxca,maxca)
+      real*8 rx(maxca,maxca)
+      real*8 ry(maxca,maxca),rz(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+      real*8 dis(maxca,maxca)
+      real*8 shefx(maxca,12),shefy(maxca,12)
+      real*8 shefz(maxca,12)
+      real*8 dp45,dm45,w_beta
+      real*8  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      integer    inb,nmax,iselect
+cc**********************************************************************
+      common /phys1/     inb,nmax,iselect
+      common /kyori2/    dis
+      common /difvec/   rx,ry,rz
+      common /sheparm/  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      common /sheconst/ dp45,dm45,w_beta
+      common /she/     vbetap,vbetam,vbetap1,vbetap2,vbetam1,vbetam2
+      common /shepin/  pin1,pin2,pin3,pin4,pina1,pina2,pina3,pina4
+      common /shef/   shefx,shefy,shefz
+ci      integer istrand(maxca,maxca)
+ci      integer istrand_p(maxca,maxca),istrand_m(maxca,maxca)
+ci      common  /shetest/ istrand,istrand_p,istrand_m
+c********************************************************************************
+c     local variables
+      integer i,imm,im,jp,jpp,j
+      real*8 yy1,y1x,y1y,y1z,y11x,y11y,y11z,yy33,yyy3,yy3,y3x,y3y,y3z
+      real*8 yy44,yyy4a,yyy4b,yy4,y4x,y4y,y4z,yy55,yyy5,yy5,y5x,y5y,y5z
+      real*8 sx,sy,sz,sx1,sy1,sz1,sx2,sy2,sz2,y6x,y6y,y6z
+      real*8 y66x,y66y,y66z,yy6,yyy4,yyy5a,yyy5b
+      real*8 yy88,yyy8a,yyy8b,yy8,y8x,y8y,y8z,yy99,yyy9,yy9,y9x,y9y,y9z
+      real*8 yy1010,yyy10,yy10,y10x,y10y,y10z,yyy8,yyy9a,yyy9b
+c********************************************************************************
+      do i=3,inb-5
+         imm=i-2
+         im=i-1
+         do j=i+2,inb-3
+            jp=j+1
+            jpp=j+2
+            
+ci            if(istrand(imm,j).eq.1
+ci     &   .and.(istrand_p(imm,j)+istrand_m(imm,j)).ge.1) then
+
+
+            yy1=-(dis(i,jpp)-ulhb)/dlhb
+            y1x=rx(jpp,i)/dis(i,jpp)
+            y1y=ry(jpp,i)/dis(i,jpp)
+            y1z=rz(jpp,i)/dis(i,jpp)
+            y11x=yy1*y1x
+            y11y=yy1*y1y
+            y11z=yy1*y1z
+               
+            yy33=1.0D0/(dis(im,jp)*dis(im,i))
+            yyy3=pin1(imm,j)/(dis(im,i)**2)
+            yy3=-pin1(imm,j)/dshe
+            y3x=(yy33*rx(im,jp)-yyy3*rx(im,i))*yy3
+            y3y=(yy33*ry(im,jp)-yyy3*ry(im,i))*yy3
+            y3z=(yy33*rz(im,jp)-yyy3*rz(im,i))*yy3
+            
+            yy44=1.0D0/(dis(i,jpp)*dis(im,i))
+            yyy4a=pin3(imm,j)/(dis(i,jpp)**2)
+            yyy4b=pin3(imm,j)/(dis(im,i)**2)
+            yy4=-pin3(imm,j)/dshe
+            y4x=(yy44*(rx(i,jpp)-rx(im,i))+yyy4a*rx(i,jpp)
+     $           -yyy4b*rx(im,i))*yy4
+            y4y=(yy44*(ry(i,jpp)-ry(im,i))+yyy4a*ry(i,jpp)
+     $           -yyy4b*ry(im,i))*yy4
+            y4z=(yy44*(rz(i,jpp)-rz(im,i))+yyy4a*rz(i,jpp)
+     $           -yyy4b*rz(im,i))*yy4
+               
+               
+            yy55=1.0D0/(dis(i,jpp)*dis(jp,jpp))
+            yyy5=pin4(imm,j)/(dis(i,jpp)**2)
+            yy5=-pin4(imm,j)/dshe
+            y5x=(-yy55*rx(jp,jpp)+yyy5*rx(i,jpp))*yy5
+            y5y=(-yy55*ry(jp,jpp)+yyy5*ry(i,jpp))*yy5
+            y5z=(-yy55*rz(jp,jpp)+yyy5*rz(i,jpp))*yy5
+               
+            sx=y11x+y3x+y4x+y5x
+            sy=y11y+y3y+y4y+y5y
+            sz=y11z+y3z+y4z+y5z
+               
+            sx1=y3x
+            sy1=y3y
+            sz1=y3z
+            sx2=y11x+y4x+y5x
+            sy2=y11y+y4y+y5y
+            sz2=y11z+y4z+y5z
+               
+            shefx(i,5)=shefx(i,5)-sx*vbetap(imm,j)
+     $           -sx1*vbetap1(imm,j)-sx2*vbetap2(imm,j)
+            shefy(i,5)=shefy(i,5)-sy*vbetap(imm,j)
+     $           -sy1*vbetap1(imm,j)-sy2*vbetap2(imm,j)
+            shefz(i,5)=shefz(i,5)-sz*vbetap(imm,j)
+     $           -sz1*vbetap1(imm,j)-sz2*vbetap2(imm,j)
+
+!            shefx(i,5)=shefx(i,5)
+!     $           -sx1*vbetap1(imm,j)-sx2*vbetap2(imm,j)
+!            shefy(i,5)=shefy(i,5)
+!     $           -sy1*vbetap1(imm,j)-sy2*vbetap2(imm,j)
+!            shefz(i,5)=shefz(i,5)
+!     $           -sz1*vbetap1(imm,j)-sz2*vbetap2(imm,j)
+            
+            yy6=-(dis(i,jp)-uldhb)/dldhb
+            y6x=rx(jp,i)/dis(i,jp)
+            y6y=ry(jp,i)/dis(i,jp)
+            y6z=rz(jp,i)/dis(i,jp)
+            y66x=yy6*y6x
+            y66y=yy6*y6y
+            y66z=yy6*y6z
+            
+            yy88=1.0D0/(dis(im,jpp)*dis(im,i))
+            yyy8=pina1(imm,j)/(dis(im,i)**2)
+            yy8=-pina1(imm,j)/dshe
+            y8x=(yy88*rx(im,jpp)-yyy8*rx(im,i))*yy8
+            y8y=(yy88*ry(im,jpp)-yyy8*ry(im,i))*yy8
+            y8z=(yy88*rz(im,jpp)-yyy8*rz(im,i))*yy8
+            
+            yy99=1.0D0/(dis(jp,i)*dis(im,i))
+            yyy9a=pina3(imm,j)/(dis(jp,i)**2)
+            yyy9b=pina3(imm,j)/(dis(im,i)**2)
+            yy9=-pina3(imm,j)/dshe
+            y9x=(yy99*(rx(jp,i)+rx(im,i))-yyy9a*rx(jp,i)
+     $           -yyy9b*rx(im,i))*yy9
+            y9y=(yy99*(ry(jp,i)+ry(im,i))-yyy9a*ry(jp,i)
+     $           -yyy9b*ry(im,i))*yy9
+            y9z=(yy99*(rz(jp,i)+rz(im,i))-yyy9a*rz(jp,i)
+     $           -yyy9b*rz(im,i))*yy9
+            
+            yy1010=1.0D0/(dis(jp,i)*dis(jp,jpp))
+            yyy10=pina4(imm,j)/(dis(jp,i)**2)
+            yy10=-pina4(imm,j)/dshe
+            y10x=(yy1010*rx(jp,jpp)-yyy10*rx(jp,i))*yy10
+            y10y=(yy1010*ry(jp,jpp)-yyy10*ry(jp,i))*yy10
+            y10z=(yy1010*rz(jp,jpp)-yyy10*rz(jp,i))*yy10
+            
+            sx=y66x+y8x+y9x+y10x
+            sy=y66y+y8y+y9y+y10y
+            sz=y66z+y8z+y9z+y10z
+            
+            sx1=y8x
+            sy1=y8y
+            sz1=y8z
+            sx2=y66x+y9x+y10x
+            sy2=y66y+y9y+y10y
+            sz2=y66z+y9z+y10z
+            
+            shefx(i,5)=shefx(i,5)-sx*vbetam(imm,j)
+     $           -sx1*vbetam1(imm,j)-sx2*vbetam2(imm,j)
+           shefy(i,5)=shefy(i,5)-sy*vbetam(imm,j)
+     $           -sy1*vbetam1(imm,j)-sy2*vbetam2(imm,j)
+            shefz(i,5)=shefz(i,5)-sz*vbetam(imm,j)
+     $           -sz1*vbetam1(imm,j)-sz2*vbetam2(imm,j)
+
+!            shefx(i,5)=shefx(i,5)
+!     $           -sx1*vbetam1(imm,j)-sx2*vbetam2(imm,j)
+!            shefy(i,5)=shefy(i,5)
+!     $           -sy1*vbetam1(imm,j)-sy2*vbetam2(imm,j)
+!            shefz(i,5)=shefz(i,5)
+!     $           -sz1*vbetam1(imm,j)-sz2*vbetam2(imm,j)
+            
+ci          endif
+
+         enddo
+      enddo
+      
+      return
+      end
+c--------------------------------------------------------------------------c
+      subroutine sheetforce6
+      implicit none
+      integer maxca
+      parameter(maxca=800)
+cc**********************************************************************
+      real*8 vbetap(maxca,maxca),vbetam(maxca,maxca)
+      real*8 vbetap1(maxca,maxca),vbetam1(maxca,maxca)
+      real*8 vbetap2(maxca,maxca),vbetam2(maxca,maxca)
+      real*8 pin1(maxca,maxca),pin2(maxca,maxca)
+      real*8 pin3(maxca,maxca),pin4(maxca,maxca)
+      real*8 pina1(maxca,maxca),pina2(maxca,maxca)
+      real*8 pina3(maxca,maxca),pina4(maxca,maxca)
+      real*8 rx(maxca,maxca)
+      real*8 ry(maxca,maxca),rz(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+      real*8 dis(maxca,maxca)
+      real*8 shefx(maxca,12),shefy(maxca,12)
+      real*8 shefz(maxca,12)
+      real*8 dp45,dm45,w_beta
+      real*8  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      integer    inb,nmax,iselect
+cc**********************************************************************
+      common /phys1/     inb,nmax,iselect
+      common /kyori2/    dis
+      common /difvec/   rx,ry,rz
+      common /sheparm/  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      common /sheconst/ dp45,dm45,w_beta
+      common /she/     vbetap,vbetam,vbetap1,vbetap2,vbetam1,vbetam2
+      common /shepin/  pin1,pin2,pin3,pin4,pina1,pina2,pina3,pina4
+      common /shef/   shefx,shefy,shefz
+ci      integer istrand(maxca,maxca)
+ci      integer istrand_p(maxca,maxca),istrand_m(maxca,maxca)
+ci      common  /shetest/ istrand,istrand_p,istrand_m
+cc**********************************************************************
+C     local variables
+      integer  i,imm,im,jp,jpp,j,ip
+      real*8  yy1,y1x,y1y,y1z,y11x,y11y,y11z,yy33,yyy3,yy3,y3x,y3y,y3z
+      real*8  yy44,yyy4a,yyy4b,yy4,y4x,y4y,y4z,yy55,yyy5,yy5,y5x,y5y,y5z
+      real*8  sx,sy,sz,sx1,sy1,sz1,sx2,sy2,sz2,y6x,y6y,y6z,y66x,y66y
+      real*8  yy88,yyy8a,yyy8b,yy8,y8x,y8y,y8z,yy99,yyy9,yy9,y9x,y9y,y9z
+      real*8  yy1010,yyy10,yy10,y10x,y10y,y10z,yyy8,yyy9a,yyy9b,yyy4
+      real*8  yyy3a,yyy3b,y66z,yy6,yyy5a,yyy5b
+C********************************************************************************      
+      do i=2,inb-6
+         ip=i+1
+         im=i-1
+         do j=i+3,inb-3
+            jp=j+1
+            jpp=j+2
+
+ci        if(istrand(im,j).eq.1
+ci     &    .and.(istrand_p(im,j)+istrand_m(im,j)).ge.1) then
+
+            
+            yy1=-(dis(i,jp)-ulhb)/dlhb
+            y1x=rx(jp,i)/dis(i,jp)
+            y1y=ry(jp,i)/dis(i,jp)
+            y1z=rz(jp,i)/dis(i,jp)
+            y11x=yy1*y1x
+            y11y=yy1*y1y
+            y11z=yy1*y1z
+            
+            yy33=1.0D0/(dis(i,jp)*dis(i,ip))
+            yyy3a=pin1(im,j)/(dis(i,jp)**2)
+            yyy3b=pin1(im,j)/(dis(i,ip)**2)
+            yy3=-pin1(im,j)/dshe
+            y3x=(-yy33*(rx(i,ip)+rx(i,jp))+yyy3a*rx(i,jp)
+     $           +yyy3b*rx(i,ip))*yy3
+            y3y=(-yy33*(ry(i,ip)+ry(i,jp))+yyy3a*ry(i,jp)
+     $           +yyy3b*ry(i,ip))*yy3
+            y3z=(-yy33*(rz(i,ip)+rz(i,jp))+yyy3a*rz(i,jp)
+     $           +yyy3b*rz(i,ip))*yy3
+            
+            yy44=1.0D0/(dis(i,jp)*dis(jp,jpp))
+            yyy4=pin2(im,j)/(dis(i,jp)**2)
+            yy4=-pin2(im,j)/dshe
+            y4x=(-yy44*rx(jp,jpp)+yyy4*rx(i,jp))*yy4
+            y4y=(-yy44*ry(jp,jpp)+yyy4*ry(i,jp))*yy4
+            y4z=(-yy44*rz(jp,jpp)+yyy4*rz(i,jp))*yy4
+            
+            yy55=1.0D0/(dis(ip,jpp)*dis(i,ip))
+            yyy5=pin3(im,j)/(dis(i,ip)**2)
+            yy5=-pin3(im,j)/dshe
+            y5x=(-yy55*rx(ip,jpp)+yyy5*rx(i,ip))*yy5
+            y5y=(-yy55*ry(ip,jpp)+yyy5*ry(i,ip))*yy5
+            y5z=(-yy55*rz(ip,jpp)+yyy5*rz(i,ip))*yy5
+            
+            sx=y11x+y3x+y4x+y5x
+            sy=y11y+y3y+y4y+y5y
+            sz=y11z+y3z+y4z+y5z
+            
+            sx1=y11x+y3x+y4x
+            sy1=y11y+y3y+y4y
+            sz1=y11z+y3z+y4z
+            sx2=y5x
+            sy2=y5y
+            sz2=y5z
+            
+            shefx(i,6)=shefx(i,6)-sx*vbetap(im,j)
+     $           -sx1*vbetap1(im,j)-sx2*vbetap2(im,j)
+            shefy(i,6)=shefy(i,6)-sy*vbetap(im,j)
+     $           -sy1*vbetap1(im,j)-sy2*vbetap2(im,j)
+            shefz(i,6)=shefz(i,6)-sz*vbetap(im,j)
+     $           -sz1*vbetap1(im,j)-sz2*vbetap2(im,j)
+!            shefx(i,6)=shefx(i,6)
+!     $           -sx1*vbetap1(im,j)-sx2*vbetap2(im,j)
+!            shefy(i,6)=shefy(i,6)
+!     $           -sy1*vbetap1(im,j)-sy2*vbetap2(im,j)
+!            shefz(i,6)=shefz(i,6)
+!     $           -sz1*vbetap1(im,j)-sz2*vbetap2(im,j)
+            
+            yy6=-(dis(jpp,i)-uldhb)/dldhb
+            y6x=rx(jpp,i)/dis(jpp,i)
+            y6y=ry(jpp,i)/dis(jpp,i)
+            y6z=rz(jpp,i)/dis(jpp,i)
+            y66x=yy6*y6x
+            y66y=yy6*y6y
+            y66z=yy6*y6z
+            
+            yy88=1.0D0/(dis(i,jpp)*dis(i,ip))
+            yyy8a=pina1(im,j)/(dis(i,jpp)**2)
+            yyy8b=pina1(im,j)/(dis(i,ip)**2)
+            yy8=-pina1(im,j)/dshe
+            y8x=(-yy88*(rx(i,jpp)+rx(i,ip))+yyy8a*rx(i,jpp)
+     $           +yyy8b*rx(i,ip))*yy8
+            y8y=(-yy88*(ry(i,jpp)+ry(i,ip))+yyy8a*ry(i,jpp)
+     $           +yyy8b*ry(i,ip))*yy8
+            y8z=(-yy88*(rz(i,jpp)+rz(i,ip))+yyy8a*rz(i,jpp)
+     $           +yyy8b*rz(i,ip))*yy8
+            
+            yy99=1.0D0/(dis(i,jpp)*dis(jp,jpp))
+            yyy9=pina2(im,j)/(dis(i,jpp)**2)
+            yy9=-pina2(im,j)/dshe
+            y9x=(-yy99*rx(jp,jpp)+yyy9*rx(i,jpp))*yy9
+            y9y=(-yy99*ry(jp,jpp)+yyy9*ry(i,jpp))*yy9
+            y9z=(-yy99*rz(jp,jpp)+yyy9*rz(i,jpp))*yy9
+            
+            yy1010=1.0D0/(dis(jp,ip)*dis(i,ip))
+            yyy10=pina3(im,j)/(dis(i,ip)**2)
+            yy10=-pina3(im,j)/dshe
+            y10x=(-yy1010*rx(jp,ip)+yyy10*rx(i,ip))*yy10
+            y10y=(-yy1010*ry(jp,ip)+yyy10*ry(i,ip))*yy10
+            y10z=(-yy1010*rz(jp,ip)+yyy10*rz(i,ip))*yy10
+            
+            sx=y66x+y8x+y9x+y10x
+            sy=y66y+y8y+y9y+y10y
+            sz=y66z+y8z+y9z+y10z
+            
+            sx1=y66x+y8x+y9x
+            sy1=y66y+y8y+y9y
+            sz1=y66z+y8z+y9z
+            sx2=y10x
+            sy2=y10y
+            sz2=y10z
+            
+            shefx(i,6)=shefx(i,6)-sx*vbetam(im,j)
+     $           -sx1*vbetam1(im,j)-sx2*vbetam2(im,j)
+           shefy(i,6)=shefy(i,6)-sy*vbetam(im,j)
+     $           -sy1*vbetam1(im,j)-sy2*vbetam2(im,j)
+            shefz(i,6)=shefz(i,6)-sz*vbetam(im,j)
+     $           -sz1*vbetam1(im,j)-sz2*vbetam2(im,j)
+
+!            shefx(i,6)=shefx(i,6)
+!     $           -sx1*vbetam1(im,j)-sx2*vbetam2(im,j)
+!           shefy(i,6)=shefy(i,6)
+!     $           -sy1*vbetam1(im,j)-sy2*vbetam2(im,j)
+!            shefz(i,6)=shefz(i,6)
+!     $           -sz1*vbetam1(im,j)-sz2*vbetam2(im,j)
+          
+ci         endif
+     
+         enddo
+      enddo
+      
+      return
+      end
+c-----------------------------------------------------------------------
+      subroutine sheetforce11
+      implicit none
+      integer maxca
+      parameter(maxca=800)
+cc**********************************************************************
+      real*8 vbetap(maxca,maxca),vbetam(maxca,maxca)
+      real*8 vbetap1(maxca,maxca),vbetam1(maxca,maxca)
+      real*8 vbetap2(maxca,maxca),vbetam2(maxca,maxca)
+      real*8 pin1(maxca,maxca),pin2(maxca,maxca)
+      real*8 pin3(maxca,maxca),pin4(maxca,maxca)
+      real*8 pina1(maxca,maxca),pina2(maxca,maxca)
+      real*8 pina3(maxca,maxca),pina4(maxca,maxca)
+      real*8 rx(maxca,maxca)
+      real*8 ry(maxca,maxca),rz(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+      real*8 dis(maxca,maxca)
+      real*8 shefx(maxca,12),shefy(maxca,12)
+      real*8 shefz(maxca,12)
+      real*8 dp45,dm45,w_beta
+      real*8  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      integer    inb,nmax,iselect
+cc**********************************************************************
+      common /phys1/     inb,nmax,iselect
+      common /kyori2/    dis
+      common /difvec/   rx,ry,rz
+      common /sheparm/  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      common /sheconst/ dp45,dm45,w_beta
+      common /she/     vbetap,vbetam,vbetap1,vbetap2,vbetam1,vbetam2
+      common /shepin/  pin1,pin2,pin3,pin4,pina1,pina2,pina3,pina4
+      common /shef/   shefx,shefy,shefz
+ci      integer istrand(maxca,maxca)
+ci      integer istrand_p(maxca,maxca),istrand_m(maxca,maxca)
+ci      common  /shetest/ istrand,istrand_p,istrand_m
+C********************************************************************************
+C     local variables
+      integer  j,jm,jmm,ip,i,ipp
+      real*8  yy1,y1x,y1y,y1z,y11x,y11y,y11z,yy33,yyy3,yy3,y3x,y3y,y3z
+      real*8  yy44,yyy4a,yyy4b,yy4,y4x,y4y,y4z,yy55,yyy5,yy5,y5x,y5y
+      real*8  sx,sy,sz,sx1,sy1,sz1,sx2,sy2,sz2,y6x,y6y,y6z,y66x,y66y
+      real*8  yy88,yyy8a,yyy8b,yy8,y8x,y8y,y8z,yy99,yyy9,yy9,y9x,y9y
+      real*8  yy1010,yyy10,yy10,y10x,y10y,y10z,yyy4,yyy5a,yyy5b,yy6
+      real*8  yyy9a,yyy9b,y5z,y66z,y9z,yyy8
+C********************************************************************************          
+      
+      do j=7,inb-1
+         jm=j-1
+         jmm=j-2
+         do i=1,j-6
+            ip=i+1
+            ipp=i+2
+
+ci            if(istrand(i,jmm).eq.1
+ci     &   .and.(istrand_p(i,jmm)+istrand_m(i,jmm)).ge.1) then
+
+               
+            yy1=-(dis(ipp,j)-ulhb)/dlhb
+            y1x=rx(ipp,j)/dis(ipp,j)
+            y1y=ry(ipp,j)/dis(ipp,j)
+            y1z=rz(ipp,j)/dis(ipp,j)
+            y11x=yy1*y1x
+            y11y=yy1*y1y
+            y11z=yy1*y1z
+            
+            yy33=1.0D0/(dis(ip,jm)*dis(jm,j))
+            yyy3=pin2(i,jmm)/(dis(jm,j)**2)
+            yy3=-pin2(i,jmm)/dshe
+            y3x=(yy33*rx(ip,jm)-yyy3*rx(jm,j))*yy3
+            y3y=(yy33*ry(ip,jm)-yyy3*ry(jm,j))*yy3
+            y3z=(yy33*rz(ip,jm)-yyy3*rz(jm,j))*yy3
+            
+            yy44=1.0D0/(dis(ipp,j)*dis(ip,ipp))
+            yyy4=pin3(i,jmm)/(dis(ipp,j)**2)
+            yy4=-pin3(i,jmm)/dshe
+            y4x=(yy44*rx(ip,ipp)-yyy4*rx(ipp,j))*yy4
+            y4y=(yy44*ry(ip,ipp)-yyy4*ry(ipp,j))*yy4
+            y4z=(yy44*rz(ip,ipp)-yyy4*rz(ipp,j))*yy4
+            
+            yy55=1.0D0/(dis(ipp,j)*dis(jm,j))
+            yyy5a=pin4(i,jmm)/(dis(ipp,j)**2)
+            yyy5b=pin4(i,jmm)/(dis(jm,j)**2)
+            yy5=-pin4(i,jmm)/dshe
+            y5x=(yy55*(rx(jm,j)+rx(ipp,j))-yyy5a*rx(ipp,j)
+     $           -yyy5b*rx(jm,j))*yy5
+            y5y=(yy55*(ry(jm,j)+ry(ipp,j))-yyy5a*ry(ipp,j)
+     $           -yyy5b*ry(jm,j))*yy5
+            y5z=(yy55*(rz(jm,j)+rz(ipp,j))-yyy5a*rz(ipp,j)
+     $           -yyy5b*rz(jm,j))*yy5
+            
+            sx=y11x+y3x+y4x+y5x
+            sy=y11y+y3y+y4y+y5y
+            sz=y11z+y3z+y4z+y5z
+            
+            sx1=y3x
+            sy1=y3y
+            sz1=y3z
+            sx2=y11x+y4x+y5x
+            sy2=y11y+y4y+y5y
+            sz2=y11z+y4z+y5z
+            
+            shefx(j,11)=shefx(j,11)-sx*vbetap(i,jmm)
+     $           -sx1*vbetap1(i,jmm)-sx2*vbetap2(i,jmm)
+            shefy(j,11)=shefy(j,11)-sy*vbetap(i,jmm)
+     $           -sy1*vbetap1(i,jmm)-sy2*vbetap2(i,jmm)
+            shefz(j,11)=shefz(j,11)-sz*vbetap(i,jmm)
+     $           -sz1*vbetap1(i,jmm)-sz2*vbetap2(i,jmm)
+
+!            shefx(j,11)=shefx(j,11)
+!     $           -sx1*vbetap1(i,jmm)-sx2*vbetap2(i,jmm)
+!            shefy(j,11)=shefy(j,11)
+!     $           -sy1*vbetap1(i,jmm)-sy2*vbetap2(i,jmm)
+!            shefz(j,11)=shefz(j,11)
+!     $           -sz1*vbetap1(i,jmm)-sz2*vbetap2(i,jmm)
+            
+            yy6=-(dis(ip,j)-uldhb)/dldhb
+            y6x=rx(ip,j)/dis(ip,j)
+            y6y=ry(ip,j)/dis(ip,j)
+            y6z=rz(ip,j)/dis(ip,j)
+            y66x=yy6*y6x
+            y66y=yy6*y6y
+            y66z=yy6*y6z
+            
+            yy88=1.0D0/(dis(ip,j)*dis(ip,ipp))
+            yyy8=pina1(i,jmm)/(dis(ip,j)**2)
+            yy8=-pina1(i,jmm)/dshe
+            y8x=(yy88*rx(ip,ipp)-yyy8*rx(ip,j))*yy8
+            y8y=(yy88*ry(ip,ipp)-yyy8*ry(ip,j))*yy8
+            y8z=(yy88*rz(ip,ipp)-yyy8*rz(ip,j))*yy8
+            
+            yy99=1.0D0/(dis(ip,j)*dis(jm,j))
+            yyy9a=pina2(i,jmm)/(dis(ip,j)**2)
+            yyy9b=pina2(i,jmm)/(dis(jm,j)**2)
+            yy9=-pina2(i,jmm)/dshe
+            y9x=(yy99*(rx(jm,j)+rx(ip,j))-yyy9a*rx(ip,j)
+     $           -yyy9b*rx(jm,j))*yy9
+            y9y=(yy99*(ry(jm,j)+ry(ip,j))-yyy9a*ry(ip,j)
+     $           -yyy9b*ry(jm,j))*yy9
+            y9z=(yy99*(rz(jm,j)+rz(ip,j))-yyy9a*rz(ip,j)
+     $           -yyy9b*rz(jm,j))*yy9
+            
+            yy1010=1.0D0/(dis(jm,ipp)*dis(jm,j))
+            yyy10=pina4(i,jmm)/(dis(jm,j)**2)
+            yy10=-pina4(i,jmm)/dshe
+            y10x=(yy1010*rx(jm,ipp)-yyy10*rx(jm,j))*yy10
+            y10y=(yy1010*ry(jm,ipp)-yyy10*ry(jm,j))*yy10
+            y10z=(yy1010*rz(jm,ipp)-yyy10*rz(jm,j))*yy10
+            
+            sx=y66x+y8x+y9x+y10x
+            sy=y66y+y8y+y9y+y10y
+            sz=y66z+y8z+y9z+y10z
+            
+            sx1=y66x+y8x+y9x
+            sy1=y66y+y8y+y9y
+            sz1=y66z+y8z+y9z
+            sx2=y10x
+            sy2=y10y
+            sz2=y10z
+            
+            shefx(j,11)=shefx(j,11)-sx*vbetam(i,jmm)
+     $           -sx1*vbetam1(i,jmm)-sx2*vbetam2(i,jmm)
+           shefy(j,11)=shefy(j,11)-sy*vbetam(i,jmm)
+     $           -sy1*vbetam1(i,jmm)-sy2*vbetam2(i,jmm)
+            shefz(j,11)=shefz(j,11)-sz*vbetam(i,jmm)
+     $           -sz1*vbetam1(i,jmm)-sz2*vbetam2(i,jmm)
+
+!            shefx(j,11)=shefx(j,11)
+!     $           -sx1*vbetam1(i,jmm)-sx2*vbetam2(i,jmm)
+!            shefy(j,11)=shefy(j,11)
+!     $           -sy1*vbetam1(i,jmm)-sy2*vbetam2(i,jmm)
+!            shefz(j,11)=shefz(j,11)
+!     $           -sz1*vbetam1(i,jmm)-sz2*vbetam2(i,jmm)
+      
+ci         endif
+         
+         enddo
+      enddo
+      
+      return
+      end
+c-----------------------------------------------------------------------
+      subroutine sheetforce12
+      implicit none
+      integer maxca
+      parameter(maxca=800)
+cc**********************************************************************
+      real*8 vbetap(maxca,maxca),vbetam(maxca,maxca)
+      real*8 vbetap1(maxca,maxca),vbetam1(maxca,maxca)
+      real*8 vbetap2(maxca,maxca),vbetam2(maxca,maxca)
+      real*8 pin1(maxca,maxca),pin2(maxca,maxca)
+      real*8 pin3(maxca,maxca),pin4(maxca,maxca)
+      real*8 pina1(maxca,maxca),pina2(maxca,maxca)
+      real*8 pina3(maxca,maxca),pina4(maxca,maxca)
+      real*8 rx(maxca,maxca)
+      real*8 ry(maxca,maxca),rz(maxca,maxca)
+      real*8 bx(maxca),by(maxca),bz(maxca)
+      real*8 dis(maxca,maxca)
+      real*8 shefx(maxca,12),shefy(maxca,12)
+      real*8 shefz(maxca,12)
+      real*8 dp45,dm45,w_beta
+      real*8  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      integer    inb,nmax,iselect
+cc**********************************************************************
+      common /phys1/     inb,nmax,iselect
+      common /kyori2/    dis
+      common /difvec/   rx,ry,rz
+      common /sheparm/  dca,dlhb,ulhb,dshe,dldhb,uldhb,
+     $     c00,s00,ulnex,dnex
+      common /sheconst/ dp45,dm45,w_beta
+      common /she/     vbetap,vbetam,vbetap1,vbetap2,vbetam1,vbetam2
+      common /shepin/  pin1,pin2,pin3,pin4,pina1,pina2,pina3,pina4
+      common /shef/   shefx,shefy,shefz
+ci      integer istrand(maxca,maxca)
+ci      integer istrand_p(maxca,maxca),istrand_m(maxca,maxca)
+ci      common  /shetest/ istrand,istrand_p,istrand_m
+cc**********************************************************************
+C     local variables
+      integer j,jm,jmm,ip,i,ipp,jp
+      real*8 yy1,y1x,y1y,y1z,y11x,y11y,y11z,yy33,yyy3,yy3,y3x,y3y,y3z
+      real*8 yy44,yyy4a,yyy4b,yy4,y4x,y4y,y4z,yy55,yyy5,yy5,y5x,y5y,y5z
+      real*8 sx,sy,sz,sx1,sy1,sz1,sx2,sy2,sz2,y6x,y6y,y6z,y66x,y66y,y66z
+      real*8 yy88,yyy8a,yyy8b,yy8,y8x,y8y,y8z,yy99,yyy9,yy9,y9x,y9y,y9z
+      real*8 yy1010,yyy10,yy10,y10x,y10y,y10z,yyy10a,yyy10b,yy6,yyy8
+!c*************************************************************************c      
+      do j=6,inb-2
+         jp=j+1
+         jm=j-1
+         do i=1,j-5
+            ip=i+1
+            ipp=i+2
+
+ci            if(istrand(i,jm).eq.1
+ci     &   .and.(istrand_p(i,jm)+istrand_m(i,jm)).ge.1) then
+
+            
+            yy1=-(dis(ip,j)-ulhb)/dlhb
+            y1x=rx(ip,j)/dis(ip,j)
+            y1y=ry(ip,j)/dis(ip,j)
+            y1z=rz(ip,j)/dis(ip,j)
+            y11x=y1x*yy1
+            y11y=y1y*yy1
+            y11z=y1z*yy1
+            
+            yy33=1.0D0/(dis(ip,j)*dis(ip,ipp))
+            yyy3=pin1(i,jm)/(dis(ip,j)**2)
+            yy3=-pin1(i,jm)/dshe
+            y3x=(yy33*rx(ip,ipp)-yyy3*rx(ip,j))*yy3
+            y3y=(yy33*ry(ip,ipp)-yyy3*ry(ip,j))*yy3
+            y3z=(yy33*rz(ip,ipp)-yyy3*rz(ip,j))*yy3
+            yy44=1.0D0/(dis(ip,j)*dis(j,jp))
+            
+            yyy4a=pin2(i,jm)/(dis(ip,j)**2)
+            yyy4b=pin2(i,jm)/(dis(j,jp)**2)
+            yy4=-pin2(i,jm)/dshe
+            y4x=(yy44*(rx(j,jp)-rx(ip,j))-yyy4a*rx(ip,j)
+     $           +yyy4b*rx(j,jp))*yy4
+            y4y=(yy44*(ry(j,jp)-ry(ip,j))-yyy4a*ry(ip,j)
+     $           +yyy4b*ry(j,jp))*yy4
+            y4z=(yy44*(rz(j,jp)-rz(ip,j))-yyy4a*rz(ip,j)
+     $           +yyy4b*rz(j,jp))*yy4
+            
+            yy55=1.0D0/(dis(ipp,jp)*dis(j,jp))
+            yyy5=pin4(i,jm)/(dis(j,jp)**2)
+            yy5=-pin4(i,jm)/dshe
+            y5x=(-yy55*rx(ipp,jp)+yyy5*rx(j,jp))*yy5
+            y5y=(-yy55*ry(ipp,jp)+yyy5*ry(j,jp))*yy5
+            y5z=(-yy55*rz(ipp,jp)+yyy5*rz(j,jp))*yy5
+            
+            sx=y11x+y3x+y4x+y5x
+            sy=y11y+y3y+y4y+y5y
+            sz=y11z+y3z+y4z+y5z
+            
+            sx1=y11x+y3x+y4x
+            sy1=y11y+y3y+y4y
+            sz1=y11z+y3z+y4z
+            sx2=y5x
+            sy2=y5y
+            sz2=y5z
+            
+            shefx(j,12)=shefx(j,12)-sx*vbetap(i,jm)
+     $           -sx1*vbetap1(i,jm)-sx2*vbetap2(i,jm)
+            shefy(j,12)=shefy(j,12)-sy*vbetap(i,jm)
+     $           -sy1*vbetap1(i,jm)-sy2*vbetap2(i,jm)
+            shefz(j,12)=shefz(j,12)-sz*vbetap(i,jm)
+     $           -sz1*vbetap1(i,jm)-sz2*vbetap2(i,jm)
+
+!            shefx(j,12)=shefx(j,12)
+!     $           -sx1*vbetap1(i,jm)-sx2*vbetap2(i,jm)
+!            shefy(j,12)=shefy(j,12)
+!     $           -sy1*vbetap1(i,jm)-sy2*vbetap2(i,jm)
+!            shefz(j,12)=shefz(j,12)
+!     $           -sz1*vbetap1(i,jm)-sz2*vbetap2(i,jm)
+            
+            yy6=-(dis(ipp,j)-uldhb)/dldhb
+            y6x=rx(ipp,j)/dis(ipp,j)
+            y6y=ry(ipp,j)/dis(ipp,j)
+            y6z=rz(ipp,j)/dis(ipp,j)
+            y66x=yy6*y6x
+            y66y=yy6*y6y
+            y66z=yy6*y6z
+            
+            yy88=1.0D0/(dis(ip,jp)*dis(j,jp))
+            yyy8=pina2(i,jm)/(dis(j,jp)**2)
+            yy8=-pina2(i,jm)/dshe
+            y8x=(-yy88*rx(ip,jp)+yyy8*rx(j,jp))*yy8
+            y8y=(-yy88*ry(ip,jp)+yyy8*ry(j,jp))*yy8
+            y8z=(-yy88*rz(ip,jp)+yyy8*rz(j,jp))*yy8
+            
+            yy99=1.0D0/(dis(j,ipp)*dis(ip,ipp))
+            yyy9=pina3(i,jm)/(dis(j,ipp)**2)
+            yy9=-pina3(i,jm)/dshe
+            y9x=(-yy99*rx(ip,ipp)+yyy9*rx(j,ipp))*yy9
+            y9y=(-yy99*ry(ip,ipp)+yyy9*ry(j,ipp))*yy9
+            y9z=(-yy99*rz(ip,ipp)+yyy9*rz(j,ipp))*yy9
+            
+            yy1010=1.0D0/(dis(j,ipp)*dis(j,jp))
+            yyy10a=pina4(i,jm)/(dis(j,ipp)**2)
+            yyy10b=pina4(i,jm)/(dis(j,jp)**2)
+            yy10=-pina4(i,jm)/dshe
+            y10x=(-yy1010*(rx(j,ipp)+rx(j,jp))+yyy10a*rx(j,ipp)
+     $           +yyy10b*rx(j,jp))*yy10
+            y10y=(-yy1010*(ry(j,ipp)+ry(j,jp))+yyy10a*ry(j,ipp)
+     $           +yyy10b*ry(j,jp))*yy10
+            y10z=(-yy1010*(rz(j,ipp)+rz(j,jp))+yyy10a*rz(j,ipp)
+     $           +yyy10b*rz(j,jp))*yy10
+            
+            sx=y66x+y8x+y9x+y10x
+            sy=y66y+y8y+y9y+y10y
+            sz=y66z+y8z+y9z+y10z
+            
+            sx1=y8x
+            sy1=y8y
+            sz1=y8z
+            sx2=y66x+y9x+y10x
+            sy2=y66y+y9y+y10y
+            sz2=y66z+y9z+y10z
+            
+            shefx(j,12)=shefx(j,12)-sx*vbetam(i,jm)
+     $           -sx1*vbetam1(i,jm)-sx2*vbetam2(i,jm)
+           shefy(j,12)=shefy(j,12)-sy*vbetam(i,jm)
+     $           -sy1*vbetam1(i,jm)-sy2*vbetam2(i,jm)
+            shefz(j,12)=shefz(j,12)-sz*vbetam(i,jm)
+     $           -sz1*vbetam1(i,jm)-sz2*vbetam2(i,jm)
+      
+ci         endif
+         
+         ENDDO
+      ENDDO
+      
+      RETURN
+      END
+C===============================================================================
index 4f753e4..5707b4b 100644 (file)
@@ -27,6 +27,7 @@ cMS$ATTRIBUTES C ::  proc_proc
 #ifdef MPI      
 c      print*,"ETOTAL Processor",fg_rank," absolute rank",myrank,
 c     & " nfgtasks",nfgtasks
+      call flush(iout)
       if (nfgtasks.gt.1) then
 #ifdef MPI
         time00=MPI_Wtime()
@@ -131,6 +132,31 @@ C
 C Calculate electrostatic (H-bonding) energy of the main chain.
 C
   107 continue
+C     BARTEK for dfa test!
+      if (wdfa_dist.gt.0) then 
+        call edfad(edfadis)
+      else
+        edfadis=0
+      endif
+c      print*, 'edfad is finished!', edfadis
+      if (wdfa_tor.gt.0) then
+        call edfat(edfator)
+      else
+        edfator=0
+      endif
+c      print*, 'edfat is finished!', edfator
+      if (wdfa_nei.gt.0) then
+        call edfan(edfanei)
+      else
+        edfanei=0
+      endif    
+c      print*, 'edfan is finished!', edfanei
+      if (wdfa_beta.gt.0) then 
+        call edfab(edfabet)
+      else
+        edfabet=0
+      endif
+c      print*, 'edfab is finished!', edfabet
 cmc
 cmc Sep-06: egb takes care of dynamic ss bonds too
 cmc
@@ -228,6 +254,15 @@ cd    print *,'nterm=',nterm
        etors=0
        edihcnstr=0
       endif
+
+      if (constr_homology.ge.1) then
+        call e_modeller(ehomology_constr)
+      else
+        ehomology_constr=0.0d0
+      endif
+
+
+c      write(iout,*) ehomology_constr
 c      print *,"Processor",myrank," computed Utor"
 C
 C 6/23/01 Calculate double-torsional energy
@@ -329,6 +364,11 @@ C
       energia(21)=esccor
       energia(22)=evdw_p
       energia(23)=evdw_m
+      energia(24)=ehomology_constr
+      energia(25)=edfadis
+      energia(26)=edfator
+      energia(27)=edfanei
+      energia(28)=edfabet
 c      print *," Processor",myrank," calls SUM_ENERGY"
       call sum_energy(energia,.true.)
       if (dyn_ss) call dyn_set_nss
@@ -426,20 +466,29 @@ cMS$ATTRIBUTES C ::  proc_proc
       estr=energia(17)
       Uconst=energia(20)
       esccor=energia(21)
+      ehomology_constr=energia(24)
+      edfadis=energia(25)
+      edfator=energia(26)
+      edfanei=energia(27)
+      edfabet=energia(28)
 #ifdef SPLITELE
       etot=wsc*evdw+wscp*evdw2+welec*ees+wvdwpp*evdw1
      & +wang*ebe+wtor*etors+wscloc*escloc
      & +wstrain*ehpb+wcorr*ecorr+wcorr5*ecorr5
      & +wcorr6*ecorr6+wturn4*eello_turn4+wturn3*eello_turn3
      & +wturn6*eturn6+wel_loc*eel_loc+edihcnstr+wtor_d*etors_d
-     & +wbond*estr+Uconst+wsccor*esccor
+     & +wbond*estr+Uconst+wsccor*esccor+ehomology_constr
+     & +wdfa_dist*edfadis+wdfa_tor*edfator+wdfa_nei*edfanei
+     & +wdfa_beta*edfabet    
 #else
       etot=wsc*evdw+wscp*evdw2+welec*(ees+evdw1)
      & +wang*ebe+wtor*etors+wscloc*escloc
      & +wstrain*ehpb+wcorr*ecorr+wcorr5*ecorr5
      & +wcorr6*ecorr6+wturn4*eello_turn4+wturn3*eello_turn3
      & +wturn6*eturn6+wel_loc*eel_loc+edihcnstr+wtor_d*etors_d
-     & +wbond*estr+Uconst+wsccor*esccor
+     & +wbond*estr+Uconst+wsccor*esccor+ehomology_constr
+     & +wdfa_dist*edfadis+wdfa_tor*edfator+wdfa_nei*edfanei
+     & +wdfa_beta*edfabet    
 #endif
       energia(0)=etot
 c detecting NaNQ
@@ -546,7 +595,11 @@ c      enddo
      &                wcorr5*gradcorr5_long(j,i)+
      &                wcorr6*gradcorr6_long(j,i)+
      &                wturn6*gcorr6_turn_long(j,i)+
-     &                wstrain*ghpbc(j,i)
+     &                wstrain*ghpbc(j,i)+
+     &                wdfa_dist*gdfad(j,i)+
+     &                wdfa_tor*gdfat(j,i)+
+     &                wdfa_nei*gdfan(j,i)+
+     &                wdfa_beta*gdfab(j,i)
         enddo
       enddo 
 #else
@@ -560,7 +613,11 @@ c      enddo
      &                wcorr5*gradcorr5_long(j,i)+
      &                wcorr6*gradcorr6_long(j,i)+
      &                wturn6*gcorr6_turn_long(j,i)+
-     &                wstrain*ghpbc(j,i)
+     &                wstrain*ghpbc(j,i)+
+     &                wdfa_dist*gdfad(j,i)+
+     &                wdfa_tor*gdfat(j,i)+
+     &                wdfa_nei*gdfan(j,i)+
+     &                wdfa_beta*gdfab(j,i)
         enddo
       enddo 
 #endif
@@ -576,7 +633,11 @@ c      enddo
      &                wcorr5*gradcorr5_long(j,i)+
      &                wcorr6*gradcorr6_long(j,i)+
      &                wturn6*gcorr6_turn_long(j,i)+
-     &                wstrain*ghpbc(j,i)
+     &                wstrain*ghpbc(j,i)+
+     &                wdfa_dist*gdfad(j,i)+
+     &                wdfa_tor*gdfat(j,i)+
+     &                wdfa_nei*gdfan(j,i)+
+     &                wdfa_beta*gdfab(j,i)
         enddo
       enddo 
 #endif
@@ -1048,6 +1109,13 @@ C------------------------------------------------------------------------
       estr=energia(17)
       Uconst=energia(20)
       esccor=energia(21)
+      ehomology_constr=energia(24)
+C     Bartek
+      edfadis = energia(25)
+      edfator = energia(26)
+      edfanei = energia(27)
+      edfabet = energia(28)
+
 #ifdef SPLITELE
       write (iout,10) evdw,wsc,evdw2,wscp,ees,welec,evdw1,wvdwpp,
      &  estr,wbond,ebe,wang,
@@ -1055,8 +1123,9 @@ C------------------------------------------------------------------------
      &  ecorr,wcorr,
      &  ecorr5,wcorr5,ecorr6,wcorr6,eel_loc,wel_loc,eello_turn3,wturn3,
      &  eello_turn4,wturn4,eello_turn6,wturn6,esccor,wsccor,
-     &  edihcnstr,ebr*nss,
-     &  Uconst,etot
+     &  edihcnstr,ehomology_constr, ebr*nss,
+     &  Uconst,edfadis,wdfa_dist,edfator,wdfa_tor,edfanei,wdfa_nei,
+     &  edfabet,wdfa_beta,etot
    10 format (/'Virtual-chain energies:'//
      & 'EVDW=  ',1pE16.6,' WEIGHT=',1pE16.6,' (SC-SC)'/
      & 'EVDW2= ',1pE16.6,' WEIGHT=',1pE16.6,' (SC-p)'/
@@ -1078,8 +1147,13 @@ C------------------------------------------------------------------------
      & 'ETURN6=',1pE16.6,' WEIGHT=',1pE16.6,' (turns, 6th order)'/
      & 'ESCCOR=',1pE16.6,' WEIGHT=',1pE16.6,' (backbone-rotamer corr)'/
      & 'EDIHC= ',1pE16.6,' (dihedral angle constraints)'/
+     & 'H_CONS=',1pE16.6,' (Homology model constraints energy)'/
      & 'ESS=   ',1pE16.6,' (disulfide-bridge intrinsic energy)'/
      & 'UCONST= ',1pE16.6,' (Constraint energy)'/ 
+     & 'EDFAD= ',1pE16.6,' WEIGHT=',1pE16.6,' (DFA distance energy)'/ 
+     & 'EDFAT= ',1pE16.6,' WEIGHT=',1pE16.6,' (DFA torsion energy)'/ 
+     & 'EDFAN= ',1pE16.6,' WEIGHT=',1pE16.6,' (DFA NCa energy)'/ 
+     & 'EDFAB= ',1pE16.6,' WEIGHT=',1pE16.6,' (DFA Beta energy)'/ 
      & 'ETOT=  ',1pE16.6,' (total)')
 #else
       write (iout,10) evdw,wsc,evdw2,wscp,ees,welec,
@@ -1088,7 +1162,9 @@ C------------------------------------------------------------------------
      &  ecorr,wcorr,
      &  ecorr5,wcorr5,ecorr6,wcorr6,eel_loc,wel_loc,eello_turn3,wturn3,
      &  eello_turn4,wturn4,eello_turn6,wturn6,esccor,wsccro,edihcnstr,
-     &  ebr*nss,Uconst,etot
+     &  ehomology_constr,ebr*nss,Uconst,edfadis,wdfa_dist,edfator,
+     &  wdfa_tor,edfanei,wdfa_nei,edfabet,wdfa_beta,
+     &  etot
    10 format (/'Virtual-chain energies:'//
      & 'EVDW=  ',1pE16.6,' WEIGHT=',1pD16.6,' (SC-SC)'/
      & 'EVDW2= ',1pE16.6,' WEIGHT=',1pD16.6,' (SC-p)'/
@@ -1109,8 +1185,13 @@ C------------------------------------------------------------------------
      & 'ETURN6=',1pE16.6,' WEIGHT=',1pD16.6,' (turns, 6th order)'/
      & 'ESCCOR=',1pE16.6,' WEIGHT=',1pD16.6,' (backbone-rotamer corr)'/
      & 'EDIHC= ',1pE16.6,' (dihedral angle constraints)'/
+     & 'H_CONS=',1pE16.6,' (Homology model constraints energy)'/
      & 'ESS=   ',1pE16.6,' (disulfide-bridge intrinsic energy)'/
      & 'UCONST=',1pE16.6,' (Constraint energy)'/ 
+     & 'EDFAD= ',1pE16.6,' WEIGHT=',1pD16.6,' (DFA distance energy)'/ 
+     & 'EDFAT= ',1pE16.6,' WEIGHT=',1pD16.6,' (DFA torsion energy)'/ 
+     & 'EDFAN= ',1pE16.6,' WEIGHT=',1pD16.6,' (DFA NCa energy)'/ 
+     & 'EDFAB= ',1pE16.6,' WEIGHT=',1pD16.6,' (DFA Beta energy)'/ 
      & 'ETOT=  ',1pE16.6,' (total)')
 #endif
       return
@@ -4637,7 +4718,7 @@ C Derivatives of the "mean" values in gamma1 and gamma2.
      &      'ebend',i,ethetai
         if (i.gt.3) gloc(i-3,icg)=gloc(i-3,icg)+wang*E_tc*dthetg1
         if (i.lt.nres) gloc(i-2,icg)=gloc(i-2,icg)+wang*E_tc*dthetg2
-        gloc(nphi+i-2,icg)=wang*(E_theta+E_tc*dthett)
+        gloc(nphi+i-2,icg)=wang*(E_theta+E_tc*dthett)+gloc(nphi+i-2,icg)
       enddo
 C Ufff.... We've done all this!!! 
       return
@@ -4936,7 +5017,7 @@ c        lprn1=.false.
         etheta=etheta+ethetai
         if (i.gt.3) gloc(i-3,icg)=gloc(i-3,icg)+wang*dephii
         if (i.lt.nres) gloc(i-2,icg)=gloc(i-2,icg)+wang*dephii1
-        gloc(nphi+i-2,icg)=wang*dethetai
+        gloc(nphi+i-2,icg)=gloc(nphi+i-2,icg)+wang*dethetai
       enddo
       return
       end
@@ -5760,6 +5841,15 @@ C Proline-Proline pair is a special case...
       return
       end
 c------------------------------------------------------------------------------
+c LICZENIE WIEZOW Z ROWNANIA ENERGII MODELLERA
+      subroutine e_modeller(ehomology_constr)
+      ehomology_constr=0.0
+      write (iout,*) "!!!!!UWAGA, JESTEM W DZIWNEJ PETLI, TEST!!!!!"
+      return
+      end
+C !!!!!!!! NIE CZYTANE !!!!!!!!!!!
+
+c------------------------------------------------------------------------------
       subroutine etor_d(etors_d)
       etors_d=0.0d0
       return
@@ -5860,6 +5950,186 @@ cd       write (iout,*) 'edihcnstr',edihcnstr
       return
       end
 c----------------------------------------------------------------------------
+c MODELLER restraint function
+      subroutine e_modeller(ehomology_constr)
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+
+      integer nnn, i, j, k, ki, irec, l
+      integer katy, odleglosci, test7
+      real*8 odleg, odleg2, odleg3, kat, kat2, kat3, gdih(max_template)
+      real*8 distance(max_template),distancek(max_template),
+     &    min_odl,godl(max_template),dih_diff(max_template)
+
+      include 'COMMON.SBRIDGE'
+      include 'COMMON.CHAIN'
+      include 'COMMON.GEO'
+      include 'COMMON.DERIV'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.VAR'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.MD'
+      include 'COMMON.CONTROL'
+
+
+      do i=1,19
+        distancek(i)=9999999.9
+      enddo
+
+
+      odleg=0.0d0
+
+c Pseudo-energy and gradient from homology restraints (MODELLER-like
+c function)
+C AL 5/2/14 - Introduce list of restraints
+      do ii = link_start_homo,link_end_homo
+         i = ires_homo(ii)
+         j = jres_homo(ii)
+         dij=dist(i,j)
+         do k=1,constr_homology
+           distance(k)=odl(k,ii)-dij
+           distancek(k)=0.5d0*waga_dist*distance(k)**2*sigma_odl(k,ii)
+         enddo
+         
+         min_odl=minval(distancek)
+#ifdef DEBUG
+         write (iout,*) "ij dij",i,j,dij
+         write (iout,*) "distance",(distance(k),k=1,constr_homology)
+         write (iout,*) "distancek",(distancek(k),k=1,constr_homology)
+         write (iout,* )"min_odl",min_odl
+#endif
+         odleg2=0.0d0
+         do k=1,constr_homology
+c Nie wiem po co to liczycie jeszcze raz!
+c            odleg3=-waga_dist*((distance(i,j,k)**2)/ 
+c     &              (2*(sigma_odl(i,j,k))**2))
+            godl(k)=dexp(-distancek(k)+min_odl)
+            odleg2=odleg2+godl(k)
+
+ccc       write(iout,779) i,j,k, "odleg2=",odleg2, "odleg3=", odleg3,
+ccc     & "dEXP(odleg3)=", dEXP(odleg3),"distance(i,j,k)^2=",
+ccc     & distance(i,j,k)**2, "dist(i+1,j+1)=", dist(i+1,j+1),
+ccc     & "sigma_odl(i,j,k)=", sigma_odl(i,j,k)
+
+         enddo
+#ifdef DEBUG
+         write (iout,*) "godl",(godl(k),k=1,constr_homology)
+         write (iout,*) "ii i j",ii,i,j," odleg2",odleg2
+#endif
+         odleg=odleg-dLOG(odleg2/constr_homology)+min_odl
+c Gradient
+         sum_godl=odleg2
+         sum_sgodl=0.0
+         do k=1,constr_homology
+c            godl=dexp(((-(distance(i,j,k)**2)/(2*(sigma_odl(i,j,k))**2))
+c     &           *waga_dist)+min_odl
+           sgodl=-godl(k)*distance(k)*sigma_odl(k,ii)*waga_dist
+           sum_sgodl=sum_sgodl+sgodl
+
+c            sgodl2=sgodl2+sgodl
+c      write(iout,*) i, j, k, distance(i,j,k), "W GRADIENCIE1"
+c      write(iout,*) "constr_homology=",constr_homology
+c      write(iout,*) i, j, k, "TEST K"
+         enddo
+
+         grad_odl3=sum_sgodl/(sum_godl*dij)
+
+
+c      write(iout,*) i, j, k, distance(i,j,k), "W GRADIENCIE2"
+c      write(iout,*) (distance(i,j,k)**2), (2*(sigma_odl(i,j,k))**2),
+c     &              (-(distance(i,j,k)**2)/(2*(sigma_odl(i,j,k))**2))
+
+ccc      write(iout,*) godl, sgodl, grad_odl3
+
+c          grad_odl=grad_odl+grad_odl3
+
+         do jik=1,3
+            ggodl=grad_odl3*(c(jik,i)-c(jik,j))
+ccc      write(iout,*) c(jik,i+1), c(jik,j+1), (c(jik,i+1)-c(jik,j+1))
+ccc      write(iout,746) "GRAD_ODL_1", i, j, jik, ggodl, 
+ccc     &              ghpbc(jik,i+1), ghpbc(jik,j+1)
+            ghpbc(jik,i)=ghpbc(jik,i)+ggodl
+            ghpbc(jik,j)=ghpbc(jik,j)-ggodl
+ccc      write(iout,746) "GRAD_ODL_2", i, j, jik, ggodl,
+ccc     &              ghpbc(jik,i+1), ghpbc(jik,j+1)
+
+         enddo
+ccc       write(iout,778)"TEST: odleg2=", odleg2, "DLOG(odleg2)=", 
+ccc     & dLOG(odleg2),"-odleg=", -odleg
+
+      enddo ! ii
+c Pseudo-energy and gradient from dihedral-angle restraints from
+c homology templates
+c      write (iout,*) "End of distance loop"
+c      call flush(iout)
+      kat=0.0d0
+c      write (iout,*) idihconstr_start_homo,idihconstr_end_homo
+      do i=idihconstr_start_homo,idihconstr_end_homo
+        kat2=0.0d0
+c        betai=beta(i,i+1,i+2,i+3)
+        betai = phi(i+3)
+        do k=1,constr_homology
+          dih_diff(k)=pinorm(dih(k,i)-betai)
+c          if (dih_diff(i,k).gt.3.14159) dih_diff(i,k)=
+c     &                                   -(6.28318-dih_diff(i,k))
+c          if (dih_diff(i,k).lt.-3.14159) dih_diff(i,k)=
+c     &                                   6.28318+dih_diff(i,k)
+
+          kat3=-0.5d0*waga_angle*dih_diff(k)**2*sigma_dih(k,i)
+          gdih(k)=dexp(kat3)
+          kat2=kat2+gdih(k)
+c          write(iout,*) "kat2=", kat2, "exp(kat3)=", exp(kat3)
+c          write(*,*)""
+        enddo
+#ifdef DEBUG
+        write (iout,*) "i",i," betai",betai," kat2",kat2
+        write (iout,*) "gdih",(gdih(k),k=1,constr_homology)
+#endif
+        if (kat2.le.1.0d-14) cycle
+        kat=kat-dLOG(kat2/constr_homology)
+
+ccc       write(iout,778)"TEST: kat2=", kat2, "DLOG(kat2)=",
+ccc     & dLOG(kat2), "-kat=", -kat
+
+c ----------------------------------------------------------------------
+c Gradient
+c ----------------------------------------------------------------------
+
+        sum_gdih=kat2
+        sum_sgdih=0.0
+        do k=1,constr_homology
+          sgdih=-gdih(k)*dih_diff(k)*sigma_dih(k,i)*waga_angle
+          sum_sgdih=sum_sgdih+sgdih
+        enddo
+        grad_dih3=sum_sgdih/sum_gdih
+
+c      write(iout,*)i,k,gdih,sgdih,beta(i+1,i+2,i+3,i+4),grad_dih3
+ccc      write(iout,747) "GRAD_KAT_1", i, nphi, icg, grad_dih3,
+ccc     & gloc(nphi+i-3,icg)
+        gloc(i,icg)=gloc(i,icg)+grad_dih3
+ccc      write(iout,747) "GRAD_KAT_2", i, nphi, icg, grad_dih3,
+ccc     & gloc(nphi+i-3,icg)
+
+      enddo
+
+
+c Total energy from homology restraints
+#ifdef DEBUG
+      write (iout,*) "odleg",odleg," kat",kat
+#endif
+      ehomology_constr=odleg+kat
+      return
+
+  748 format(a8,f12.3,a6,f12.3,a7,f12.3)
+  747 format(a12,i4,i4,i4,f8.3,f8.3)
+  746 format(a12,i4,i4,i4,f8.3,f8.3,f8.3)
+  778 format(a7,1X,f10.3,1X,a4,1X,f10.3,1X,a5,1X,f10.3)
+  779 format(i3,1X,i3,1X,i2,1X,a7,1X,f7.3,1X,a7,1X,f7.3,1X,a13,1X,
+     &       f7.3,1X,a17,1X,f9.3,1X,a10,1X,f8.3,1X,a10,1X,f8.3)
+      end
+
+c------------------------------------------------------------------------------
       subroutine etor_d(etors_d)
 C 6/23/01 Compute double torsional energy
       implicit real*8 (a-h,o-z)
index 81e4d81..97442a3 100644 (file)
@@ -263,6 +263,7 @@ cMS$ATTRIBUTES C ::  proc_proc
       include 'COMMON.CHAIN'
       include 'COMMON.VAR'
       include 'COMMON.LOCAL'
+      include 'COMMON.CONTROL'
 
 c      write(iout,'(a,i2)')'Calling etotal_short ipot=',ipot
 c      call flush(iout)
@@ -395,6 +396,16 @@ C
 C Calculate electrostatic (H-bonding) energy of the main chain.
 C
   107 continue
+
+C     BARTEK for dfa test!
+      if (wdfa_dist.gt.0) call edfad(edfadis)
+c      print*, 'edfad is finished!', edfadis
+      if (wdfa_tor.gt.0) call edfat(edfator)
+c      print*, 'edfat is finished!', edfator
+      if (wdfa_nei.gt.0) call edfan(edfanei)
+c      print*, 'edfan is finished!', edfanei
+      if (wdfa_beta.gt.0) call edfab(edfabet)
+c      print*, 'edfab is finished!', edfabet
 c
 c Calculate the short-range part of Evdwpp
 c
@@ -426,6 +437,14 @@ C
 C Calculate the virtual-bond torsional energy.
 C
       call etor(etors,edihcnstr)
+c
+c Homology restraints
+c
+      if (constr_homology.ge.1) then
+        call e_modeller(ehomology_constr)
+      else
+        ehomology_constr=0.0d0
+      endif
 C
 C 6/23/01 Calculate double-torsional energy
 C
@@ -467,6 +486,11 @@ C
       energia(21)=esccor
       energia(22)=evdw_p
       energia(23)=evdw_m
+      energia(24)=ehomology_constr
+      energia(25)=edfadis
+      energia(26)=edfator
+      energia(27)=edfanei
+      energia(28)=edfabet
 c      write (iout,*) "ETOTAL_SHORT before SUM_ENERGY"
       call flush(iout)
       call sum_energy(energia,.true.)
index df698f5..a5c6f96 100644 (file)
@@ -471,12 +471,12 @@ c-----------------------------------------------------------------
         if (print_compon) then
           if(itime.eq.0) then
            write(format,'(a1,a4,a1,a4,a10)') "(",format1,",",format2,
-     &                                                     ",20a12)"
+     &                                                     ",100a12)"
            write (istat,format) "#","",
      &      (ename(print_order(i)),i=1,nprint_ene)
           endif
           write(format,'(a1,a4,a1,a4,a10)') "(",format1,",",format2,
-     &                                                     ",20f12.3)"
+     &                                                     ",100f12.3)"
           write (istat,format) line1,line2,
      &      (potEcomp(print_order(i)),i=1,nprint_ene)
         else
index 565ccaf..d02ebd1 100644 (file)
@@ -264,15 +264,16 @@ c-------------------------------------------------------------------------
      &   "EVDW SC-SC","EVDW2 SC-p","EES p-p","ECORR4 ","ECORR5 ",
      &   "ECORR6 ","EELLO ","ETURN3 ","ETURN4 ","ETURN6 ",
      &   "EBE bend","ESC SCloc","ETORS ","ETORSD ","EHPB ","EVDWPP ",
-     &   "ESTR ","EVDW2_14 ","UCONST ", "      ","ESCCOR"," "," "/
+     &   "ESTR ","EVDW2_14 ","UCONST ", "      ","ESCCOR"," "," ",
+     &   "Ehomology","DFA DIS","DFA TOR","DFA NEI","DFA BET"/
       data wname /
      &   "WSC","WSCP","WELEC","WCORR","WCORR5","WCORR6","WEL_LOC",
      &   "WTURN3","WTURN4","WTURN6","WANG","WSCLOC","WTOR","WTORD",
      &   "WSTRAIN","WVDWPP","WBOND","SCAL14","     ","    ","WSCCOR",
-     &   " "," "/
-      data nprint_ene /20/
+     &   " "," ","EHOMO","WDFAD","WDFAT","WDFAN","WDFAB"/
+      data nprint_ene /25/
       data print_order/1,2,3,11,12,13,14,4,5,6,7,8,9,10,19,18,15,17,16,
-     & 21,0,0,0/
+     & 21,24,25,26,27,28,0,0,0/
       end 
 c---------------------------------------------------------------------------
       subroutine init_int_table
@@ -292,6 +293,7 @@ c---------------------------------------------------------------------------
       include 'COMMON.IOUNITS'
       include 'COMMON.DERIV'
       include 'COMMON.CONTACTS'
+      include 'COMMON.MD'
       common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
      & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
      & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
@@ -1392,3 +1394,46 @@ c      write(2,*)"hpb_partition: nhpb=",nhpb
 c      write(2,*)"hpb_partition: link_start=",nhpb," link_end=",link_end
       return
       end
+c------------------------------------------------------------------------------
+      subroutine homology_partition
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+#ifdef MPI
+      include 'mpif.h'
+#endif
+      include 'COMMON.SBRIDGE'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.SETUP'
+      include 'COMMON.CONTROL'
+      include 'COMMON.MD'
+      include 'COMMON.INTERACT'
+      write(iout,*)"homology_partition: lim_odl=",lim_odl,
+     &   " lim_dih",lim_dih
+#ifdef MPI
+      write (iout,*) "MPI"
+      call int_bounds(lim_odl,link_start_homo,link_end_homo)
+      call int_bounds(lim_dih-nnt+1,idihconstr_start_homo,
+     &  idihconstr_end_homo)
+      idihconstr_start_homo=idihconstr_start_homo+nnt-1
+      idihconstr_end_homo=idihconstr_end_homo+nnt-1
+      if (me.eq.king .or. .not. out1file) 
+     &  write (iout,*) 'Processor',fg_rank,' CG group',kolor,
+     &  ' absolute rank',MyRank,
+     &  ' lim_odl',lim_odl,' link_start=',link_start_homo,
+     &  ' link_end',link_end_homo,' lim_dih',lim_dih,
+     &  ' idihconstr_start_homo',idihconstr_start_homo,
+     &  ' idihconstr_end_homo',idihconstr_end_homo
+#else
+      write (iout,*) "Not MPI"
+      link_start_homo=1
+      link_end_homo=lim_odl
+      idihconstr_start_homo=nnt
+      idihconstr_end_homo=lim_dih
+      write (iout,*) 
+     &  ' lim_odl',lim_odl,' link_start=',link_start_homo,
+     &  ' link_end',link_end_homo,' lim_dih',lim_dih,
+     &  ' idihconstr_start_homo',idihconstr_start_homo,
+     &  ' idihconstr_end_homo',idihconstr_end_homo
+#endif
+      return
+      end
index 48e0abd..3ce8334 100644 (file)
@@ -13,18 +13,30 @@ C geometry.
       include 'COMMON.CONTROL'
       include 'COMMON.DISTFIT'
       include 'COMMON.SETUP'
-      character*3 seq,atom,res
-      character*80 card
-      dimension sccor(3,20)
+      integer i,j,ibeg,ishift1,ires,iii,ires_old,ishift,ity,
+     &  ishift_pdb
+      logical lprn /.true./,fail
       double precision e1(3),e2(3),e3(3)
-      logical fail
+      double precision dcj,efree_temp
+      character*3 seq,res
+      character*5 atom
+      character*80 card
+      double precision sccor(3,20)
       integer rescode
+      efree_temp=0.0d0
       ibeg=1
+      ishift1=0
+      ishift=0
+c      write (2,*) "UNRES_PDB",unres_pdb
+      ires=0
+      ires_old=0
+      iii=0
       lsecondary=.false.
       nhfrag=0
       nbfrag=0
       do i=1,10000
         read (ipdbin,'(a80)',end=10) card
+c        write (iout,'(a)') card
         if (card(:5).eq.'HELIX') then
          nhfrag=nhfrag+1
          lsecondary=.true.
@@ -43,86 +55,118 @@ crc  to be corrected !!!
 crc----------------------------------------
         endif
         if (card(:3).eq.'END' .or. card(:3).eq.'TER') goto 10
+c Read free energy
+        if (index(card,"FREE ENERGY").gt.0) read(card(35:),*) efree_temp
 C Fish out the ATOM cards.
         if (index(card(1:4),'ATOM').gt.0) then  
-          read (card(14:16),'(a3)') atom
-          if (atom.eq.'CA' .or. atom.eq.'CH3') then
+          read (card(12:16),*) atom
+c          write (iout,*) "! ",atom," !",ires
+c          if (atom.eq.'CA' .or. atom.eq.'CH3') then
+          read (card(23:26),*) ires
+          read (card(18:20),'(a3)') res
+c          write (iout,*) "ires",ires,ires-ishift+ishift1,
+c     &      " ires_old",ires_old
+c          write (iout,*) "ishift",ishift," ishift1",ishift1
+c          write (iout,*) "IRES",ires-ishift+ishift1,ires_old
+          if (ires-ishift+ishift1.ne.ires_old) then
 C Calculate the CM of the preceding residue.
+c            if (ibeg.eq.0) call sccenter(ires,iii,sccor)
             if (ibeg.eq.0) then
+c              write (iout,*) "Calculating sidechain center iii",iii
               if (unres_pdb) then
                 do j=1,3
-                  dc(j,ires+nres)=sccor(j,iii)
+                  dc(j,ires)=sccor(j,iii)
                 enddo
               else
-                call sccenter(ires,iii,sccor)
+                call sccenter(ires_old,iii,sccor)
               endif
+              iii=0
             endif
 C Start new residue.
-            read (card(24:26),*) ires
-            read (card(18:20),'(a3)') res
-            if (ibeg.eq.1) then
+            if (res.eq.'Cl-' .or. res.eq.'Na+') then
+              ires=ires_old
+              cycle
+            else if (ibeg.eq.1) then
+c              write (iout,*) "BEG ires",ires
               ishift=ires-1
               if (res.ne.'GLY' .and. res.ne. 'ACE') then
                 ishift=ishift-1
                 itype(1)=21
               endif
+              ires=ires-ishift+ishift1
+              ires_old=ires
+c              write (iout,*) "ishift",ishift," ires",ires,
+c     &         " ires_old",ires_old
               ibeg=0          
+            else
+              ishift=ishift-(ires-ishift+ishift1-ires_old-1)
+              ires=ires-ishift+ishift1
+              ires_old=ires
             endif
-            ires=ires-ishift
-            if (res.eq.'ACE') then
-              ity=10
+            if (res.eq.'ACE' .or. res.eq.'NHE') then
+              itype(ires)=10
             else
               itype(ires)=rescode(ires,res,0)
             endif
+          else
+            ires=ires-ishift+ishift1
+          endif
+c          write (iout,*) "ires_old",ires_old," ires",ires
+          if (card(27:27).eq."A" .or. card(27:27).eq."B") then
+c            ishift1=ishift1+1
+          endif
+c          write (2,*) "ires",ires," res ",res," ity",ity
+          if (atom.eq.'CA' .or. atom.eq.'CH3' .or. 
+     &       res.eq.'NHE'.and.atom(:2).eq.'HN') then
             read(card(31:54),'(3f8.3)') (c(j,ires),j=1,3)
-c            if(me.eq.king.or..not.out1file)
-c     &       write (iout,'(2i3,2x,a,3f8.3)') 
-c     &       ires,itype(ires),res,(c(j,ires),j=1,3)
-            iii=1
+c            write (iout,*) "backbone ",atom 
+#ifdef DEBUG
+            write (iout,'(2i3,2x,a,3f8.3)') 
+     &      ires,itype(ires),res,(c(j,ires),j=1,3)
+#endif
+            iii=iii+1
             do j=1,3
               sccor(j,iii)=c(j,ires)
             enddo
-          else if (atom.ne.'O  '.and.atom(1:1).ne.'H' .and. 
-     &             atom.ne.'N  ' .and. atom.ne.'C   ') then
+            if (ishift.ne.0) then
+              ires_ca=ires+ishift-ishift1
+            else
+              ires_ca=ires
+            endif
+c            write (*,*) card(23:27),ires,itype(ires)
+          else if (atom.ne.'O'.and.atom(1:1).ne.'H' .and.
+     &             atom.ne.'N' .and. atom.ne.'C' .and.
+     &             atom(:2).ne.'1H' .and. atom(:2).ne.'2H' .and.
+     &             atom.ne.'OXT' .and. atom(:2).ne.'3H') then
+c            write (iout,*) "sidechain ",atom
             iii=iii+1
             read(card(31:54),'(3f8.3)') (sccor(j,iii),j=1,3)
           endif
         endif
       enddo
-   10 if(me.eq.king.or..not.out1file) 
-     & write (iout,'(a,i5)') ' Nres: ',ires
+   10 write (iout,'(a,i5)') ' Number of residues found: ',ires
+      if (ires.eq.0) return
 C Calculate the CM of the last side chain.
+      if (iii.gt.0)  then
       if (unres_pdb) then
         do j=1,3
-          dc(j,ires+nres)=sccor(j,iii)
+          dc(j,ires)=sccor(j,iii)
         enddo
-      else 
+      else
         call sccenter(ires,iii,sccor)
       endif
+      endif
       nres=ires
       nsup=nres
       nstart_sup=1
       if (itype(nres).ne.10) then
         nres=nres+1
         itype(nres)=21
-        if (unres_pdb) then
-C 2/15/2013 by Adam: corrected insertion of the last dummy residue
-          call refsys(nres-3,nres-2,nres-1,e1,e2,e3,fail)
-          if (fail) then
-            e2(1)=0.0d0
-            e2(2)=1.0d0
-            e2(3)=0.0d0
-          endif
-          do j=1,3
-            c(j,nres)=c(j,nres-1)-3.8d0*e2(j)
-          enddo
-        else
         do j=1,3
           dcj=c(j,nres-2)-c(j,nres-3)
           c(j,nres)=c(j,nres-1)+dcj
           c(j,2*nres)=c(j,nres)
         enddo
-        endif
       endif
       do i=2,nres-1
         do j=1,3
@@ -155,6 +199,24 @@ C 2/15/2013 by Adam: corrected insertion of the first dummy residue
         enddo
         endif
       endif
+C Copy the coordinates to reference coordinates
+c      do i=1,2*nres
+c        do j=1,3
+c          cref(j,i)=c(j,i)
+c        enddo
+c      enddo
+C Calculate internal coordinates.
+      if (lprn) then
+      write (iout,'(/a)') 
+     &  "Cartesian coordinates of the reference structure"
+      write (iout,'(a,3(3x,a5),5x,3(3x,a5))') 
+     & "Residue","X(CA)","Y(CA)","Z(CA)","X(SC)","Y(SC)","Z(SC)"
+      do ires=1,nres
+        write (iout,'(a3,1x,i3,3f8.3,5x,3f8.3)') 
+     &    restyp(itype(ires)),ires,(c(j,ires),j=1,3),
+     &    (c(j,ires+nres),j=1,3)
+      enddo
+      endif
 C Calculate internal coordinates.
       if(me.eq.king.or..not.out1file)then
        write (iout,'(a)') 
@@ -205,7 +267,7 @@ C Copy the coordinates to reference coordinates
          hfrag(i,j)=hfrag(i,j)-ishift
         enddo
       enddo
-
+      ishift_pdb=ishift
       return
       end
 c---------------------------------------------------------------------------
@@ -224,7 +286,8 @@ c---------------------------------------------------------------------------
       include 'COMMON.NAMES'
       include 'COMMON.CONTROL'
       include 'COMMON.SETUP'
-      character*3 seq,atom,res
+      character*3 seq,res
+c      character*5 atom
       character*80 card
       dimension sccor(3,20)
       integer rescode
index b861fdb..d21d3b9 100644 (file)
@@ -96,6 +96,7 @@ c      print *,"Processor",me," fg_rank",fg_rank," out1file",out1file
 C Set up the time limit (caution! The time must be input in minutes!)
       read_cart=index(controlcard,'READ_CART').gt.0
       call readi(controlcard,'CONSTR_DIST',constr_dist,0)
+      call readi(controlcard,'CONSTR_HOMOL',constr_homology,0)
       call reada(controlcard,'TIMLIM',timlim,960.0D0) ! default 16 hours
       unres_pdb = index(controlcard,'UNRES_PDB') .gt. 0
       call reada(controlcard,'SAFETY',safety,30.0D0) ! default 30 minutes
@@ -749,6 +750,10 @@ C 12/1/95 Added weight for the multi-body term WCORR
        call reada(weightcard,'WTORD',wtor_d,1.0D0)
        call reada(weightcard,'WANG',wang,1.0D0)
        call reada(weightcard,'WSCLOC',wscloc,1.0D0)
+       call reada(weightcard,'WDFAD',wdfa_dist,0.0d0)
+       call reada(weightcard,'WDFAT',wdfa_tor,0.0d0)
+       call reada(weightcard,'WDFAN',wdfa_nei,0.0d0)
+       call reada(weightcard,'WDFAB',wdfa_beta,0.0d0)
        call reada(weightcard,'SCAL14',scal14,0.4D0)
        call reada(weightcard,'SCALSCP',scalscp,1.0d0)
        call reada(weightcard,'CUTOFF',cutoff_corr,7.0d0)
@@ -778,11 +783,16 @@ C 12/1/95 Added weight for the multi-body term WCORR
        weights(18)=scal14
        weights(21)=wsccor
       endif
+       weights(25)=wdfa_dist
+       weights(26)=wdfa_tor
+       weights(27)=wdfa_nei
+       weights(28)=wdfa_beta
 
       if(me.eq.king.or..not.out1file)
      & write (iout,10) wsc,wscp,welec,wvdwpp,wbond,wang,wscloc,wtor,
      &  wtor_d,wstrain,wel_loc,wcorr,wcorr5,wcorr6,wsccor,wturn3,
-     &  wturn4,wturn6
+     &  wturn4,wturn6,
+     &  wdfa_dist,wdfa_tor,wdfa_nei,wdfa_beta
    10 format (/'Energy-term weights (unscaled):'//
      & 'WSCC=   ',f10.6,' (SC-SC)'/
      & 'WSCP=   ',f10.6,' (SC-p)'/
@@ -801,7 +811,11 @@ C 12/1/95 Added weight for the multi-body term WCORR
      & 'WSCCOR= ',f10.6,' (back-scloc correlation)'/
      & 'WTURN3= ',f10.6,' (turns, 3rd order)'/
      & 'WTURN4= ',f10.6,' (turns, 4th order)'/
-     & 'WTURN6= ',f10.6,' (turns, 6th order)')
+     & 'WTURN6= ',f10.6,' (turns, 6th order)'/
+     & 'WDFA_D= ',f10.6,' (DFA, distance)'   /
+     & 'WDFA_T= ',f10.6,' (DFA, torsional)'   /
+     & 'WDFA_N= ',f10.6,' (DFA, number of neighbor)'   /
+     & 'WDFA_B= ',f10.6,' (DFA, beta formation)')
       if(me.eq.king.or..not.out1file)then
        if (wcorr4.gt.0.0d0) then
         write (iout,'(/2a/)') 'Local-electrostatic type correlation ',
@@ -829,7 +843,8 @@ C 12/1/95 Added weight for the multi-body term WCORR
       if(me.eq.king.or..not.out1file)
      & write (iout,22) wsc,wscp,welec,wvdwpp,wbond,wang,wscloc,wtor,
      &  wtor_d,wstrain,wel_loc,wcorr,wcorr5,wcorr6,wsccor,wturn3,
-     &  wturn4,wturn6
+     &  wturn4,wturn6,
+     &  wdfa_dist,wdfa_tor,wdfa_nei,wdfa_beta
    22 format (/'Energy-term weights (scaled):'//
      & 'WSCC=   ',f10.6,' (SC-SC)'/
      & 'WSCP=   ',f10.6,' (SC-p)'/
@@ -848,7 +863,11 @@ C 12/1/95 Added weight for the multi-body term WCORR
      & 'WSCCOR= ',f10.6,' (back-scloc correlatkion)'/
      & 'WTURN3= ',f10.6,' (turns, 3rd order)'/
      & 'WTURN4= ',f10.6,' (turns, 4th order)'/
-     & 'WTURN6= ',f10.6,' (turns, 6th order)')
+     & 'WTURN6= ',f10.6,' (turns, 6th order)'/
+     & 'WDFA_D= ',f10.6,' (DFA, distance)'   /
+     & 'WDFA_T= ',f10.6,' (DFA, torsional)'   /
+     & 'WDFA_N= ',f10.6,' (DFA, number of neighbor)'   /
+     & 'WDFA_B= ',f10.6,' (DFA, beta formation)')
       if(me.eq.king.or..not.out1file)
      & write (iout,*) "Reference temperature for weights calculation:",
      &  temp0
@@ -1039,6 +1058,21 @@ C 8/13/98 Set limits to generating the dihedral angles
 cd      print *,'NNT=',NNT,' NCT=',NCT
       if (itype(1).eq.21) nnt=2
       if (itype(nres).eq.21) nct=nct-1
+
+C     Bartek:READ init_vars
+C     Initialize variables!
+C     Juyong:READ read_info
+C     READ fragment information!!
+C     both routines should be in dfa.F file!!
+
+      if (.not. (wdfa_dist.eq.0.0 .and. wdfa_tor.eq.0.0 .and.
+     &            wdfa_nei.eq.0.0 .and. wdfa_beta.eq.0.0)) then
+       call init_dfa_vars
+       print*, 'init_dfa_vars finished!'
+       call read_dfa_info
+       print*, 'read_dfa_info finished!'
+      endif
+C
       if (pdbref) then
         if(me.eq.king.or..not.out1file)
      &   write (iout,'(a,i3)') 'nsup=',nsup
@@ -1128,6 +1162,13 @@ c        write (iout,*) "constr_dist",constr_dist,nstart_sup,nsup
       if (constr_dist.gt.0) then
         call read_dist_constr
       endif
+
+
+      if (constr_homology.gt.0) then
+        call read_constr_homology
+      endif
+
+
       if (nhpb.gt.0) call hpb_partition
 c      write (iout,*) "After read_dist_constr nhpb",nhpb
 c      call flush(iout)
@@ -2576,6 +2617,121 @@ c            write (iout,*) "j",j," k",k
       return
       end
 c-------------------------------------------------------------------------------
+
+      subroutine read_constr_homology
+
+      include 'DIMENSIONS'
+#ifdef MPI
+      include 'mpif.h'
+#endif
+      include 'COMMON.SETUP'
+      include 'COMMON.CONTROL'
+      include 'COMMON.CHAIN'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.MD'
+      include 'COMMON.GEO'
+      include 'COMMON.INTERACT'
+      double precision odl_temp,sigma_odl_temp
+      common /przechowalnia/ odl_temp(maxres,maxres,max_template),
+     &    sigma_odl_temp(maxres,maxres,max_template)
+      character*2 kic2
+      character*24 model_ki_dist, model_ki_angle
+      character*500 controlcard
+      integer ki, i, j, k, l
+      logical lprn /.true./
+
+      call card_concat(controlcard)
+      call reada(controlcard,"HOMOL_DIST",waga_dist,1.0d0)
+      call reada(controlcard,"HOMOL_ANGLE",waga_angle,1.0d0)
+
+      write (iout,*) "nnt",nnt," nct",nct
+      call flush(iout)
+      lim_odl=0
+      lim_dih=0
+      do i=1,nres
+        do j=i+2,nres
+          do ki=1,constr_homology
+            sigma_odl_temp(i,j,ki)=0.0d0
+            odl_temp(i,j,ki)=0.0d0
+          enddo
+        enddo
+      enddo
+      do i=1,nres-3
+        do ki=1,constr_homology
+          dih(ki,i)=0.0d0
+          sigma_dih(ki,i)=0.0d0
+        enddo
+      enddo
+      do ki=1,constr_homology
+          write(kic2,'(i2)') ki
+          if (ki.le.9) kic2="0"//kic2(2:2)
+
+          model_ki_dist="model"//kic2//".dist"
+          model_ki_angle="model"//kic2//".angle"
+        open (ientin,file=model_ki_dist,status='old')
+        do irec=1,maxdim !petla do czytania wiezow na odleglosc
+          read (ientin,*,end=1401) i, j, odl_temp(i+nnt-1,j+nnt-1,ki),
+     &       sigma_odl_temp(i+nnt-1,j+nnt-1,ki)
+          odl_temp(j+nnt-1,i+nnt-1,ki)=odl_temp(i+nnt-1,j+nnt-1,ki)
+          sigma_odl_temp(j+nnt-1,i+nnt-1,ki)=
+     &     sigma_odl_temp(i+nnt-1,j+nnt-1,ki)
+        enddo
+ 1401 continue
+        close (ientin)
+        open (ientin,file=model_ki_angle,status='old')
+        do irec=1,maxres-3 !petla do czytania wiezow na katy torsyjne
+          read (ientin,*,end=1402) i, j, k,l,dih(ki,i+nnt-1),
+     &      sigma_dih(ki,i+nnt-1)
+          if (i+nnt-1.gt.lim_dih) lim_dih=i+nnt-1
+          sigma_dih(ki,i+nnt-1)=1.0d0/sigma_dih(ki,i+nnt-1)**2
+        enddo
+ 1402 continue
+        close (ientin)
+      enddo
+      ii=0
+      write (iout,*) "nnt",nnt," nct",nct
+      do i=nnt,nct-2
+        do j=i+2,nct
+          ki=1
+c          write (iout,*) "i",i," j",j," constr_homology",constr_homology
+          do while (ki.le.constr_homology .and.
+     &        sigma_odl_temp(i,j,ki).le.0.0d0)
+c            write (iout,*) "ki",ki," sigma_odl",sigma_odl_temp(i,j,ki)
+            ki=ki+1
+          enddo
+c          write (iout,*) "ki",ki
+          if (ki.gt.constr_homology) cycle
+          ii=ii+1
+          ires_homo(ii)=i
+          jres_homo(ii)=j
+          do ki=1,constr_homology
+            odl(ki,ii)=odl_temp(i,j,ki)
+            sigma_odl(ki,ii)=1.0d0/sigma_odl_temp(i,j,ki)**2
+          enddo      
+        enddo
+      enddo
+      lim_odl=ii
+      if (constr_homology.gt.0) call homology_partition
+c Print restraints
+      if (.not.lprn) return
+      write (iout,*) "Distance restraints from templates"
+      do ii=1,lim_odl
+        write(iout,'(3i5,10(2f8.2,4x))') ii,ires_homo(ii),jres_homo(ii),
+     &  (odl(ki,ii),1.0d0/dsqrt(sigma_odl(ki,ii)),ki=1,constr_homology)
+      enddo
+      write (iout,*) "Dihedral angle restraints from templates"
+      do i=nnt,lim_dih
+        write (iout,'(i5,10(2f8.2,4x))') i,(rad2deg*dih(ki,i),
+     &      rad2deg/dsqrt(sigma_dih(ki,i)),ki=1,constr_homology)
+      enddo
+c      write(iout,*) "TEST CZYTANIA1",odl(1,2,1),odl(1,3,1),odl(1,4,1)
+c      write(iout,*) "TEST CZYTANIA2",dih(1,1),dih(2,1),dih(3,1)
+
+
+      return
+      end
+c----------------------------------------------------------------------
+
 #ifdef WINIFL
       subroutine flush(iu)
       return
@@ -2587,6 +2743,7 @@ c-------------------------------------------------------------------------------
       return
       end
 #endif
+
 c------------------------------------------------------------------------------
       subroutine copy_to_tmp(source)
       include "DIMENSIONS"
index eab3c70..15800ae 100644 (file)
@@ -532,7 +532,7 @@ c     Local variables
      &     allihpb(maxdim),alljhpb(maxdim),
      &     newnss,newihpb(maxdim),newjhpb(maxdim)
       logical found
-      integer i_newnss(max_fg_procs),displ(max_fg_procs)
+      integer i_newnss(max_fg_procs),displ(0:max_fg_procs)
       integer g_newihpb(maxdim),g_newjhpb(maxdim),g_newnss
 
       allnss=0
index fb65430..5a81655 100644 (file)
@@ -206,15 +206,15 @@ C      syssec = timar(2)
 #endif
 
 #ifdef LINUX
-****************************
+c****************************
 C Next definitions for sgi
       real timar(2), etime
       seconds = etime(timar)
 Cd    print *,'seconds=',seconds,' stime=',stime
-C      usrsec = timar(1)
-C      syssec = timar(2)
+      usrsec = timar(1)
+      syssec = timar(2)
       tcpu=seconds - stime
-****************************
+c****************************
 #endif
 
 
@@ -232,7 +232,7 @@ C     curtim=curtim(1:8)
 #ifdef AIX
 ****************************
 C Next definitions for RS6000
-       integer*4 i1,mclock
+c       integer*4 i1,mclock
        i1 = mclock()
        tcpu = (i1+0.0D0)/100.0D0
 #endif
index b14c040..632374b 100644 (file)
@@ -56,8 +56,6 @@ c      call memmon_print_usage()
       if (me.eq.king) call cinfo
 C Read force field parameters and job setup data
       call readrtns
-      call flush(iout)
-C
       if (me.eq.king .or. .not. out1file) then
        write (iout,'(2a/)') 
      & text_mode_calc(modecalc)(:ilen(text_mode_calc(modecalc))),