📄 regrow.f90
字号:
Subroutine ReGrow( Nlj, Nion, MaxMol, MaxSp, Nmol, &
Xlj, Ylj, Zlj, TYPElj, DAMPlj2, DAMPlj3, &
Xion, Yion, Zion, TYPEion, DAMPion, &
NSTEPS, MaxSteps, STEPSTART, STEPLENGTH, NTRIALS, &
MaxBeads, METHOD, MaxInt, MaxReal, INTPARAM, &
REALPARAM, BEADTYPE, BONDSAPART, BoxSize, SPECIES, &
LENGTHlj, LENGTHion, STARTlj, STARTion, PROB_SP, &
Nham, BETA, LNW, LNPSI, LnPi, XLRCORR, ELRCORR, &
Nljgrs, EPS, SIG, CP, ALP, RMAX, Niongrs, CHARGE, &
Alpha, Kmax, Nkvec, KX, KY, KZ, CONST, &
EXPX, EXPY, EXPZ, SUMQEXPV, SUMQX, SUMQY, SUMQZ, &
ULJBOX, ULJLR, UREAL, UFOURIER, USURF, USELF_CH, &
USELF_MOL, ULJ_MOL, UION_MOL, UINTRA, SpID, Success, &
Nres, Nresmol, reslen, Xresmols, &
Yresmols, Zresmols, Uint_resm, &
Ulj_resm, Uion_resm, &
f14_lj, f14_ion, Seed )
implicit none
! This subroutine regrows a flexible molecule from StartGrowthStep to the
! last step and then accepts or rejects the move.
! Nlj is the number of LJ beads in the simulation boxes.
! Nion is the number of ionic beads in the simulation boxes.
integer, intent(inout) :: Nlj
integer, intent(inout) :: Nion
! MaxMol is the maximum number of molecules per box.
! MaxSp is the maximum number of Species in the simulation.
integer, intent(in) :: MaxMol
integer, intent(in) :: MaxSp
! Nmol is the number of molecules in the simulation boxes.
! Nmol(0, iphase) ==> total number of molecules in that phase.
! Nmol(1:MaxSp, iphase) ==> number of molecules of that species in that phase.
integer, dimension(0:MaxSp), intent(inout) :: Nmol
! Xlj, Ylj, and Zlj are the coordinates of the LJ beads.
! Xion, Yion, and Zion are the coordinates of the ionic beads.
real, dimension(Nlj), intent(inout) :: Xlj, Ylj, Zlj
real, dimension(Nion), intent(inout) :: Xion, Yion, Zion
! TYPElj contains the group identity of each LJ bead.
! TYPEion contains the group identity of each ionic bead.
integer, dimension(Nlj), intent(inout) :: TYPElj
integer, dimension(Nion), intent(inout) :: TYPEion
real, dimension(Nlj), intent(inout) :: DAMPlj2, DAMPlj3
real, dimension(Nion), intent(inout) :: DAMPion
! NSTEPS is the number of configurational bias steps it takes to grow a molecule.
! MaxSteps is the maximum number of CB steps.
integer, dimension(MaxSp), intent(in) :: NSTEPS
integer, intent(in) :: MaxSteps
! STEPSTART is the start bead of each CB step.
! STEPLENGTH is the number of beads in each CB step.
! NTRIALS is the number of trial orientations/locations for each CB step.
integer, dimension(MaxSteps, MaxSp), intent(in) :: STEPSTART
integer, dimension(MaxSteps, MaxSp), intent(in) :: STEPLENGTH
integer, dimension(MaxSteps, MaxSp), intent(in) :: NTRIALS
! MaxBeads in the maximum number of beads per molecule.
! METHOD is the method used to grow each bead.
! MaxInt is the maximum number of integer parameters.
! MaxReal is the maximum number of real parameters.
! INTPARAM are the integer parameters needed by the method to grow each bead.
! REALPARAM are the real parameters needed by the method to grow each bead.
! BEADTYPE indicates whether the bead is 'LJ' or 'ION'.
! BONDSAPART gives the bondlengths any two LJ beads are away from each other.
integer, intent(in) :: MaxBeads
character*10, dimension(MaxBeads, MaxSp), intent(in) :: METHOD
integer, intent(in) :: MaxInt
integer, intent(in) :: MaxReal
integer, dimension(MaxInt, MaxBeads, MaxSp), intent(in) :: INTPARAM
real, dimension(MaxReal, MaxBeads, MaxSp), intent(in) :: REALPARAM
character*5, dimension(MaxBeads, MaxSp), intent(in) :: BEADTYPE
integer, dimension(MaxBeads,MaxBeads,MaxSp), intent(in) :: BONDSAPART
! BoxSize is the length of the simulation box.
real, intent(in) :: BoxSize
! SPECIES contains the species identity of each molecule.
! LENGTHlj contains the number of LJ beads in each molecule.
! LENGTHion contains the number of ionic beads in each molecule.
! STARTlj contains the starting LJ bead number for each molecule.
! STARTion contains the starting ionic bead number for each molecule.
integer, dimension(Nmol(0)), intent(inout) :: SPECIES
integer, dimension(Nmol(0)), intent(inout) :: LENGTHlj, LENGTHion
integer, dimension(Nmol(0)), intent(inout) :: STARTlj, STARTion
! PROB_SP contains the accumulative probability of selecting a given species.
real, dimension(MaxSp), intent(in) :: PROB_SP
! Nham is the number of hamiltonians being used.
integer, intent(in) :: Nham
! beta contains the reciprical temperature.
real, dimension(Nham), intent(in) :: BETA
! LNW contains the weight of each hamiltonian.
real, dimension(Nham), intent(inout) :: LNW
! LNPSI contains the log(psi) of each hamiltonian.
real, dimension(Nham), intent(inout) :: LNPSI
! LnPi contains the log(pi).
real, intent(inout) :: LnPi
! XLRCORR and ELRCORR contain parameters for the long range LJ energy.
real, dimension(605), intent(in) :: XLRCORR, ELRCORR
! Nljgrs is the number of LJ groups in the system.
! EPS is a rank 3 array containing the eps_ij parameters for each hamiltonian.
! SIG is a rank 3 array containing the sigma_ij parameters for each hamiltonian.
! CP is a rank 3 array containing the C_ij parameters for each hamiltonian.
! ALP is a rank 3 array containing the alpha_ij parameters for each hamiltonian.
! RMAX is a rank 3 array containing the Rmax_ij parameters for each hamiltonian.
integer, intent(in) :: Nljgrs
real, dimension(Nljgrs, Nljgrs, Nham), intent(in) :: EPS, SIG, CP, ALP, RMAX
! Niongrs is the number of ionic groups in the system.
! CHARGE is a rank 2 array containing the charge of group i for each hamiltonian.
integer, intent(in) :: Niongrs
real, dimension(Niongrs, Nham), intent(inout) :: CHARGE
! Alpha is an Ewald sum parameter, Alpha = kappa * L, for kappa in A + T.
real, intent(in) :: Alpha
! Kmax is an Ewald sum parameter.
! Nkvec is the number of k-vectors used in the Fourier sum.
! KX, KY, KZ contain the vector identity of the Nkvec vectors.
! CONST contains the constant part of the Fourier summation for a given Nkvec.
integer, intent(in) :: Kmax
integer, intent(in) :: Nkvec
integer, dimension(Nkvec), intent(in) :: KX, KY, KZ
real, dimension(Nkvec), intent(in) :: CONST
! EXPX contains the value of exp( i*kx*x ) for a given kx and ion.
complex, dimension(0:Kmax, Nion), intent(inout) :: EXPX
complex, dimension(-Kmax:Kmax, Nion), intent(inout) :: EXPY, EXPZ
! SUMQEXPV contains the summation of qi*exp(i*(kx*x + ky*y + kz*z))
! for a given k-vector and hamiltonian.
complex, dimension(Nkvec, Nham), intent(inout) :: SUMQEXPV
! SUMQX is the summation of qi * xi for all ions in the box.
real, dimension(Nham), intent(inout) :: SUMQX, SUMQY, SUMQZ
! ULJ is the LJ energy of the system without the long range correction.
! UFOURIER is the coulombic fourier energy of the system.
! UREAL is the coulombic real energy of the system.
! USURF is the coulombic surface energy of the system.
! USELF_CH is the summation of the square of all the charges.
! USELF_MOL is the self energy of a given molecule.
! ULJ_MOL is the non bonded intramolecular LJ energy of a molecule.
! UION_MOL is the non bonded intramolecular LJ energy of a molecule.
! UINTRA contains the bending and torsional energy of each molecule.
real, dimension(Nham), intent(inout) :: ULJBOX, ULJLR
real, dimension(Nham), intent(inout) :: UREAL, UFOURIER
real, dimension(Nham), intent(inout) :: USURF, USELF_CH
real, dimension(MaxMol,Nham), intent(inout) :: USELF_MOL
real, dimension(MaxMol,Nham), intent(inout) :: ULJ_MOL
real, dimension(MaxMol,Nham), intent(inout) :: UION_MOL
real, dimension(MaxMol), intent(inout) :: UINTRA
! SpID indicates which type of species was used in the move.
integer, intent(out) :: SpID
! Success is a logical indicating whether the move was successful or not.
logical, intent(out) :: Success
integer, intent(in) :: Nres, Nresmol
integer, dimension(Nres), intent(in) :: reslen
real, dimension(Nresmol, MaxBeads, Nres), intent(in) :: Xresmols, Yresmols, Zresmols
real, dimension(Nresmol, Nres), intent(in) :: Uint_resm
real, dimension(Nresmol, Nham, Nres), intent(in) :: Ulj_resm, Uion_resm
! f14_lj and f14_ion are damping factors for the 1-4 intramolecular interactions
real, intent(in) :: f14_lj
real, intent(in) :: f14_ion
! Seed is the current random number generator seed value.
integer, intent(inout) :: Seed
real, external :: ran2
! Local Variables
integer :: h, i, k
integer :: Count
integer :: MolSpecies
integer :: Mol
integer :: lenlj, lenion
integer :: lenljst, lenionst
integer :: stlj, stion
integer :: endlj, endion
integer :: StartGrowthStep
integer, dimension(Nlj) :: TYPElj_new
integer, dimension(Nion) :: TYPEion_new
integer, dimension(Nljgrs) :: NGROUPS
integer, allocatable, dimension(:) :: TYPElj_grow
integer, allocatable, dimension(:) :: TYPEion_grow
logical :: New
real :: Random
real :: LnPi_tmp, LnPi_old
real :: Largest
real :: Uintra_grow
real :: Uintra_new
real :: CoulCombo
real, dimension(Nlj) :: Xlj_new, Ylj_new, Zlj_new
real, dimension(Nion) :: Xion_new, Yion_new, Zion_new
real, dimension(Nlj) :: DAMPlj2_new, DAMPlj3_new
real, dimension(Nion) :: DAMPion_new
real, dimension(Nham) :: BIGW_old, BIGW_new
real, dimension(Nham) :: TMP, dU
real, dimension(Nham) :: ULJBOX_new, ULJLR_new
real, dimension(Nham) :: UREAL_new, UFOURIER_new
real, dimension(Nham) :: USURF_new, USELF_CH_new
real, dimension(Nham) :: USELF_MOL_new
real, dimension(Nham) :: ULJ_MOL_new
real, dimension(Nham) :: UION_MOL_new
real, dimension(Nham) :: ULJBOX_grow, ULJLR_grow
real, dimension(Nham) :: UREAL_grow, UFOURIER_grow
real, dimension(Nham) :: USURF_grow, USELF_CH_grow
real, dimension(Nham) :: USELF_MOL_grow
real, dimension(Nham) :: ULJ_MOL_grow
real, dimension(Nham) :: UION_MOL_grow
real, dimension(Nham) :: dUFOURIER
real, dimension(Nham) :: dUSURF
real, dimension(Nham) :: SUMQX_new, SUMQY_new, SUMQZ_new
real, dimension(Nham) :: SUMQX_grow, SUMQY_grow, SUMQZ_grow
real, dimension(Nljgrs, Nljgrs, Nham) :: EPS_CP
real, allocatable, dimension(:) :: Xlj_grow1, Ylj_grow1, Zlj_grow1
real, allocatable, dimension(:) :: Xion_grow1, Yion_grow1, Zion_grow1
real, allocatable, dimension(:) :: Xlj_grow2, Ylj_grow2, Zlj_grow2
real, allocatable, dimension(:) :: Xion_grow2, Yion_grow2, Zion_grow2
real, allocatable, dimension(:) :: DAMPlj2_grow, DAMPlj3_grow
real, allocatable, dimension(:) :: DAMPion_grow
real, parameter :: Pi = 3.14159265359
real, parameter :: ec = 1.60217733e-19
real, parameter :: eps0 = 8.854187817e-12
real, parameter :: kB = 1.380658e-23
complex, dimension(Nkvec, Nham) :: SUMQEXPV_new, SUMQEXPV_grow
complex, allocatable, dimension(:,:) :: EXPX_grow1, EXPY_grow1, EXPZ_grow1
complex, allocatable, dimension(:,:) :: EXPX_grow2, EXPY_grow2, EXPZ_grow2
complex, allocatable, dimension(:,:) :: CZERO1, CZERO2
CoulCombo = ec * ec * 1.0e10 / ( 4.0 * Pi * eps0 * kB )
Success = .False.
Random = ran2(Seed)
SpID = 0
i = 1
do while ( SpID == 0 )
if( Random < PROB_SP(i) ) SpID = i
i = i + 1
end do
if( Nmol(SpID) == 0 ) return
MolSpecies = int( Nmol( SpID) * ran2(Seed) ) + 1
i = 0
Count = 0
do while ( Count < MolSpecies )
i = i + 1
if( SPECIES(i) == SpID ) Count = Count + 1
end do
Mol = i
lenlj = LENGTHlj(Mol)
stlj = STARTlj(Mol)
endlj = stlj + lenlj - 1
lenion = LENGTHion(Mol)
stion = STARTion(Mol)
endion = stion + lenion - 1
if( stlj == 1 ) then
if( Nmol(0) == 1 ) then
Xlj_new = 0.0
Ylj_new = 0.0
Zlj_new = 0.0
TYPElj_new = 0
DAMPlj2_new = 0.0
DAMPlj3_new = 0.0
else
Xlj_new( 1:Nlj-lenlj ) = Xlj( endlj+1:Nlj )
Ylj_new( 1:Nlj-lenlj ) = Ylj( endlj+1:Nlj )
Zlj_new( 1:Nlj-lenlj ) = Zlj( endlj+1:Nlj )
TYPElj_new( 1:Nlj-lenlj ) = TYPElj( endlj+1:Nlj )
DAMPlj2_new( 1:Nlj-lenlj ) = DAMPlj2( endlj+1:Nlj )
DAMPlj3_new( 1:Nlj-lenlj ) = DAMPlj3( endlj+1:Nlj )
end if
else if( stlj + lenlj - 1 == Nlj ) then
Xlj_new( 1:stlj-1 ) = Xlj( 1:stlj-1 )
Ylj_new( 1:stlj-1 ) = Ylj( 1:stlj-1 )
Zlj_new( 1:stlj-1 ) = Zlj( 1:stlj-1 )
TYPElj_new( 1:stlj-1 ) = TYPElj( 1:stlj-1 )
DAMPlj2_new( 1:stlj-1 ) = DAMPlj2( 1:stlj-1 )
DAMPlj3_new( 1:stlj-1 ) = DAMPlj3( 1:stlj-1 )
else
Xlj_new( 1:stlj-1 ) = Xlj( 1:stlj-1 )
Xlj_new( stlj:Nlj-lenlj ) = Xlj( endlj+1:Nlj )
Ylj_new( 1:stlj-1 ) = Ylj( 1:stlj-1 )
Ylj_new( stlj:Nlj-lenlj ) = Ylj( endlj+1:Nlj )
Zlj_new( 1:stlj-1 ) = Zlj( 1:stlj-1 )
Zlj_new( stlj:Nlj-lenlj ) = Zlj( endlj+1:Nlj )
TYPElj_new( 1:stlj-1 ) = TYPElj( 1:stlj-1 )
TYPElj_new( stlj:Nlj-lenlj ) = TYPElj( endlj+1:Nlj )
DAMPlj2_new( 1:stlj-1 ) = DAMPlj2( 1:stlj-1 )
DAMPlj2_new( stlj:Nlj-lenlj ) = DAMPlj2( endlj+1:Nlj )
DAMPlj3_new( 1:stlj-1 ) = DAMPlj3( 1:stlj-1 )
DAMPlj3_new( stlj:Nlj-lenlj ) = DAMPlj3( endlj+1:Nlj )
end if
if( lenion > 0 ) then
if( stion == 1 ) then
if( Nmol(0) == 1 ) then
Xion_new = 0.0
Yion_new = 0.0
Zion_new = 0.0
TYPEion_new = 0
DAMPion_new = 0.0
else
Xion_new( 1:Nion-lenion ) = Xion( endion+1:Nion )
Yion_new( 1:Nion-lenion ) = Yion( endion+1:Nion )
Zion_new( 1:Nion-lenion ) = Zion( endion+1:Nion )
TYPEion_new( 1:Nion-lenion ) = TYPEion( endion+1:Nion )
DAMPion_new( 1:Nion-lenion ) = DAMPion( endion+1:Nion )
end if
else if( stion + lenion - 1 == Nion ) then
Xion_new( 1:stion-1 ) = Xion( 1:stion-1 )
Yion_new( 1:stion-1 ) = Yion( 1:stion-1 )
Zion_new( 1:stion-1 ) = Zion( 1:stion-1 )
TYPEion_new( 1:stion-1 ) = TYPEion( 1:stion-1 )
DAMPion_new( 1:stion-1 ) = DAMPion( 1:stion-1 )
else
Xion_new( 1:stion-1 ) = Xion( 1:stion-1 )
Xion_new( stion:Nion-lenion ) = Xion( endion+1:Nion )
Yion_new( 1:stion-1 ) = Yion( 1:stion-1 )
Yion_new( stion:Nion-lenion ) = Yion( endion+1:Nion )
Zion_new( 1:stion-1 ) = Zion( 1:stion-1 )
Zion_new( stion:Nion-lenion ) = Zion( endion+1:Nion )
TYPEion_new( 1:stion-1 ) = TYPEion( 1:stion-1 )
TYPEion_new( stion:Nion-lenion ) = TYPEion( endion+1:Nion )
DAMPion_new( 1:stion-1 ) = DAMPion( 1:stion-1 )
DAMPion_new( stion:Nion-lenion ) = DAMPion( endion+1:Nion )
end if
end if
allocate( Xlj_grow1(lenlj) )
allocate( Ylj_grow1(lenlj) )
allocate( Zlj_grow1(lenlj) )
allocate( Xlj_grow2(lenlj) )
allocate( Ylj_grow2(lenlj) )
allocate( Zlj_grow2(lenlj) )
allocate( TYPElj_grow(lenlj) )
allocate( DAMPlj2_grow(lenlj) )
allocate( DAMPlj3_grow(lenlj) )
! For n-alkanes only.
! If not an n-alkane (or symmetric molecule) comment
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -