114 SUBROUTINE mc_run_ensemble(mc_env, para_env, globenv, input_declaration, nboxes, rng_stream)
120 INTEGER,
INTENT(IN) :: nboxes
123 CHARACTER(len=*),
PARAMETER :: routinen =
'mc_run_ensemble'
125 CHARACTER(default_string_length),
ALLOCATABLE, &
126 DIMENSION(:) :: atom_names_box
127 CHARACTER(default_string_length), &
128 DIMENSION(:, :),
POINTER :: atom_names
129 CHARACTER(LEN=20) :: ensemble
130 CHARACTER(LEN=40) :: cbox, cstep,
fft_lib, move_type, &
132 INTEGER,
DIMENSION(:, :),
POINTER :: nchains
133 INTEGER,
DIMENSION(:),
POINTER :: avbmc_atom, mol_type, nchains_box, &
135 INTEGER,
DIMENSION(1:nboxes) :: box_flag, cl, data_unit, diff, istep, &
137 INTEGER,
DIMENSION(1:3, 1:2) :: discrete_array
138 INTEGER :: atom_number, box_number, cell_unit, com_crd, com_ene, com_mol, end_mol, handle, &
139 ibox, idum, imol_type, imolecule, imove, iparticle, iprint, itype, iunit, iuptrans, &
140 iupvolume, iw, jbox, jdum, molecule_type, molecule_type_swap, molecule_type_target, &
141 nchain_total, nmol_types, nmoves, nnstep, nstart, nstep, source, start_atom, &
142 start_atom_swap, start_atom_target, start_mol
143 CHARACTER(LEN=default_string_length) :: unit_str
144 CHARACTER(LEN=40),
DIMENSION(1:nboxes) :: cell_file, coords_file, data_file, &
145 displacement_file, energy_file, &
146 molecules_file, moves_file
147 LOGICAL :: ionode, lbias, ldiscrete, lhmc, &
148 lnew_bias_env, loverlap, lreject, &
149 lstop, print_kind, should_stop
150 REAL(
dp),
DIMENSION(:),
POINTER :: pbias, pmavbmc_mol, pmclus_box, &
151 pmhmc_box, pmrot_mol, pmtraion_mol, &
152 pmtrans_mol, pmvol_box
153 REAL(
dp),
DIMENSION(:, :),
POINTER :: conf_prob, mass
154 REAL(kind=
dp) :: discrete_step, pmavbmc, pmcltrans, &
155 pmhmc, pmswap, pmtraion, pmtrans, &
156 pmvolume, rand, test_energy, unit_conv
157 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: r_temp
158 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: r_old
159 REAL(kind=
dp),
DIMENSION(1:3, 1:nboxes) :: abc
160 REAL(kind=
dp),
DIMENSION(1:nboxes) :: bias_energy, energy_check, final_energy, &
161 initial_energy, last_bias_energy, &
173 DIMENSION(:),
POINTER :: mc_par
179 CALL timeset(routinen, handle)
182 NULLIFY (moves, move_updates, test_moves, root_section)
185 ALLOCATE (force_env(1:nboxes))
186 ALLOCATE (bias_env(1:nboxes))
187 ALLOCATE (cell(1:nboxes))
188 ALLOCATE (particles_old(1:nboxes))
189 ALLOCATE (oldsys(1:nboxes))
190 ALLOCATE (averages(1:nboxes))
191 ALLOCATE (mc_par(1:nboxes))
192 ALLOCATE (pmvol_box(1:nboxes))
193 ALLOCATE (pmclus_box(1:nboxes))
194 ALLOCATE (pmhmc_box(1:nboxes))
198 mc_par=mc_par(ibox)%mc_par, &
199 force_env=force_env(ibox)%force_env)
203 root_section => force_env(1)%force_env%root_section
212 ionode=ionode, source=source, group=group, &
213 data_file=data_file(1), moves_file=moves_file(1), &
214 cell_file=cell_file(1), coords_file=coords_file(1), &
215 energy_file=energy_file(1), displacement_file=displacement_file(1), &
216 lstop=lstop, nstep=nstep, nstart=nstart, pmvolume=pmvolume, pmhmc=pmhmc, &
217 molecules_file=molecules_file(1), pmswap=pmswap, nmoves=nmoves, &
218 pmtraion=pmtraion, pmtrans=pmtrans, pmcltrans=pmcltrans, iuptrans=iuptrans, &
219 iupvolume=iupvolume, ldiscrete=ldiscrete, pmtraion_mol=pmtraion_mol, &
220 lbias=lbias, iprint=iprint, pmavbmc_mol=pmavbmc_mol, &
221 discrete_step=discrete_step,
fft_lib=
fft_lib, avbmc_atom=avbmc_atom, &
222 pmavbmc=pmavbmc, pbias=pbias, mc_molecule_info=mc_molecule_info, &
223 pmrot_mol=pmrot_mol, pmtrans_mol=pmtrans_mol, pmvol_box=pmvol_box(1), &
224 pmclus_box=pmclus_box(1), ensemble=ensemble, pmhmc_box=pmhmc_box(1), lhmc=lhmc)
228 nchains=nchains, nmol_types=nmol_types, nunits_tot=nunits_tot, &
229 mol_type=mol_type, nchain_total=nchain_total, nunits=nunits, &
230 atom_names=atom_names, mass=mass)
233 ALLOCATE (moves(1:nmol_types, 1:nboxes))
234 ALLOCATE (move_updates(1:nmol_types, 1:nboxes))
239 data_file=data_file(ibox), &
240 moves_file=moves_file(ibox), &
241 cell_file=cell_file(ibox), coords_file=coords_file(ibox), &
242 energy_file=energy_file(ibox), &
243 displacement_file=displacement_file(ibox), &
244 molecules_file=molecules_file(ibox), pmvol_box=pmvol_box(ibox), &
245 pmclus_box=pmclus_box(ibox), pmhmc_box=pmhmc_box(ibox))
250 IF (pmvol_box(nboxes) < 1.0e0_dp)
THEN
251 cpabort(
'The last value of PMVOL_BOX needs to be 1.0')
253 IF (pmclus_box(nboxes) < 1.0e0_dp)
THEN
254 cpabort(
'The last value of PMVOL_BOX needs to be 1.0')
256 IF (pmhmc_box(nboxes) < 1.0e0_dp)
THEN
257 cpabort(
'The last value of PMHMC_BOX needs to be 1.0')
261 ALLOCATE (r_old(3, sum(nunits_tot), 1:nboxes))
269 WRITE (iw, *)
'Beginning the Monte Carlo calculation.'
275 energy_check(:) = 0.0e0_dp
282 DO itype = 1, nmol_types
289 IF (sum(nchains(:, ibox)) /= 0)
THEN
293 potential_energy=old_energy(ibox))
295 old_energy(ibox) = 0.0e0_dp
297 initial_energy(ibox) = old_energy(ibox)
304 DO jbox = 1, ibox - 1
305 start_mol = start_mol + sum(nchains(:, jbox))
307 end_mol = start_mol + sum(nchains(:, ibox)) - 1
309 nunits, loverlap, mol_type(start_mol:end_mol))
310 IF (loverlap) cpabort(
"overlap in an initial configuration")
315 subsys=oldsys(ibox)%subsys, cell=cell(ibox)%cell)
316 CALL get_cell(cell(ibox)%cell, abc=abc(:, ibox))
318 particles=particles_old(ibox)%list)
320 DO iparticle = 1, nunits_tot(ibox)
321 r_old(1:3, iparticle, ibox) = &
322 particles_old(ibox)%list%els(iparticle)%r(1:3)
328 ALLOCATE (atom_names_box(1:nunits_tot(ibox)))
331 DO imolecule = 1, sum(nchains(:, ibox))
332 DO iunit = 1, nunits(mol_type(imolecule + start_mol - 1))
333 atom_names_box(atom_number) = &
334 atom_names(iunit, mol_type(imolecule + start_mol - 1))
335 atom_number = atom_number + 1
339 CALL get_mc_par(mc_par(ibox)%mc_par, mc_bias_file=mc_bias_file)
340 nchains_box => nchains(:, ibox)
342 r_old(:, :, ibox), atom_names_box(:), nunits_tot(ibox), &
343 para_env, abc(:, ibox), nchains_box, input_declaration, mc_bias_file, &
345 IF (sum(nchains(:, ibox)) /= 0)
THEN
349 potential_energy=last_bias_energy(ibox))
352 last_bias_energy(ibox) = 0.0e0_dp
354 bias_energy(ibox) = last_bias_energy(ibox)
355 DEALLOCATE (atom_names_box)
357 lnew_bias_env = .false.
365 CALL open_file(file_name=
'mc_cell_length', &
366 unit_number=cell_unit, file_position=
'APPEND', &
367 file_action=
'WRITE', file_status=
'UNKNOWN')
368 CALL open_file(file_name=
'mc_energies', &
369 unit_number=com_ene, file_position=
'APPEND', &
370 file_action=
'WRITE', file_status=
'UNKNOWN')
371 CALL open_file(file_name=
'mc_coordinates', &
372 unit_number=com_crd, file_position=
'APPEND', &
373 file_action=
'WRITE', file_status=
'UNKNOWN')
374 CALL open_file(file_name=
'mc_molecules', &
375 unit_number=com_mol, file_position=
'APPEND', &
376 file_action=
'WRITE', file_status=
'UNKNOWN')
377 WRITE (com_ene, *)
'Initial Energies: ', &
380 WRITE (com_mol, *)
'Initial Molecules: ', &
384 WRITE (cell_unit, *)
'Initial: ', &
386 WRITE (cbox,
'(I4)') ibox
387 CALL open_file(file_name=
'energy_differences_box'// &
388 trim(adjustl(cbox)), &
389 unit_number=diff(ibox), file_position=
'APPEND', &
390 file_action=
'WRITE', file_status=
'UNKNOWN')
391 IF (sum(nchains(:, ibox)) == 0)
THEN
392 WRITE (com_crd, *)
' 0'
393 WRITE (com_crd, *)
'INITIAL BOX '//trim(adjustl(cbox))
396 com_crd,
dump_xmol,
'POS',
'INITIAL BOX '//trim(adjustl(cbox)), &
397 unit_conv=unit_conv, print_kind=print_kind)
399 CALL open_file(file_name=data_file(ibox), &
400 unit_number=data_unit(ibox), file_position=
'APPEND', &
401 file_action=
'WRITE', file_status=
'UNKNOWN')
402 CALL open_file(file_name=moves_file(ibox), &
403 unit_number=move_unit(ibox), file_position=
'APPEND', &
404 file_action=
'WRITE', file_status=
'UNKNOWN')
405 CALL open_file(file_name=displacement_file(ibox), &
406 unit_number=rm(ibox), file_position=
'APPEND', &
407 file_action=
'WRITE', file_status=
'UNKNOWN')
408 CALL open_file(file_name=cell_file(ibox), &
409 unit_number=cl(ibox), file_position=
'APPEND', &
410 file_action=
'WRITE', file_status=
'UNKNOWN')
418 CALL group%bcast(cl(ibox), source)
419 CALL group%bcast(rm(ibox), source)
420 CALL group%bcast(diff(ibox), source)
422 CALL set_mc_par(mc_par(ibox)%mc_par, cl=cl(ibox), rm=rm(ibox), &
429 IF (nboxes /= 1)
THEN
430 cpabort(
'ldiscrete=.true. ONLY for systems with 1 box')
438 IF (.NOT. lstop)
THEN
439 nstep = nstep*nchain_total
440 iuptrans = iuptrans*nchain_total
441 iupvolume = iupvolume*nchain_total
444 DO nnstep = nstart + 1, nstart + nstep
446 IF (mod(nnstep, iprint) == 0 .AND. (iw > 0))
THEN
448 WRITE (iw, *)
"------- On Monte Carlo Step ", nnstep
451 IF (ionode) rand = rng_stream%next()
453 CALL group%bcast(rand, source)
455 IF (rand < pmvolume)
THEN
457 IF (mod(nnstep, iprint) == 0 .AND. (iw > 0))
THEN
458 WRITE (iw, *)
"Attempting a volume move"
462 SELECT CASE (ensemble)
465 force_env(1)%force_env, &
466 moves(1, 1)%moves, move_updates(1, 1)%moves, &
468 energy_check(1), r_old(:, :, 1), iw, discrete_array(:, :), &
472 move_updates, nnstep, old_energy, energy_check, &
476 IF (ionode) rand = rng_stream%next()
477 CALL group%bcast(rand, source)
480 IF (rand <= pmvol_box(ibox))
THEN
487 force_env(box_number)%force_env, &
488 moves(1, box_number)%moves, &
489 move_updates(1, box_number)%moves, &
490 old_energy(box_number), box_number, &
491 energy_check(box_number), r_old(:, :, box_number), iw, &
492 discrete_array(:, :), &
499 subsys=oldsys(ibox)%subsys, cell=cell(ibox)%cell)
500 CALL get_cell(cell(ibox)%cell, abc=abc(:, ibox))
502 particles=particles_old(ibox)%list)
510 ALLOCATE (atom_names_box(1:nunits_tot(ibox)))
512 DO jbox = 1, ibox - 1
513 start_mol = start_mol + sum(nchains(:, jbox))
515 end_mol = start_mol + sum(nchains(:, ibox)) - 1
517 DO imolecule = 1, sum(nchains(:, ibox))
518 DO iunit = 1, nunits(mol_type(imolecule + start_mol - 1))
519 atom_names_box(atom_number) = &
520 atom_names(iunit, mol_type(imolecule + start_mol - 1))
521 atom_number = atom_number + 1
527 subsys=oldsys(ibox)%subsys, cell=cell(ibox)%cell)
528 CALL get_cell(cell(ibox)%cell, abc=abc(:, ibox))
531 mc_bias_file=mc_bias_file)
532 nchains_box => nchains(:, ibox)
535 r_old(:, :, ibox), atom_names_box(:), nunits_tot(ibox), &
536 para_env, abc(:, ibox), nchains_box, input_declaration, &
537 mc_bias_file, ionode)
539 IF (sum(nchains(:, ibox)) /= 0)
THEN
541 bias_env(ibox)%force_env, &
544 potential_energy=last_bias_energy(ibox))
546 last_bias_energy(ibox) = 0.0e0_dp
548 bias_energy(ibox) = last_bias_energy(ibox)
549 DEALLOCATE (atom_names_box)
553 ELSE IF (rand < pmswap)
THEN
556 IF (mod(nnstep, iprint) == 0 .AND. (iw > 0))
THEN
557 WRITE (iw, *)
"Attempting a swap move"
562 energy_check(:), r_old(:, :, :), old_energy(:), input_declaration, &
563 para_env, bias_energy(:), last_bias_energy(:), rng_stream)
567 CALL get_mc_par(mc_par(1)%mc_par, mc_molecule_info=mc_molecule_info)
569 nchains=nchains, nmol_types=nmol_types, nunits_tot=nunits_tot, &
570 mol_type=mol_type, nchain_total=nchain_total, nunits=nunits, &
571 atom_names=atom_names, mass=mass)
573 ELSE IF (rand < pmhmc)
THEN
575 IF (mod(nnstep, iprint) == 0 .AND. (iw > 0))
THEN
576 WRITE (iw, *)
"Attempting a hybrid Monte Carlo move"
581 IF (ionode) rand = rng_stream%next()
582 CALL group%bcast(rand, source)
585 IF (rand <= pmhmc_box(ibox))
THEN
592 force_env(box_number)%force_env, globenv, &
593 moves(1, box_number)%moves, &
594 move_updates(1, box_number)%moves, &
595 old_energy(box_number), box_number, &
596 energy_check(box_number), r_old(:, :, box_number), &
599 ELSE IF (rand < pmavbmc)
THEN
601 IF (mod(nnstep, iprint) == 0 .AND. (iw > 0))
THEN
602 WRITE (iw, *)
"Attempting an AVBMC1 move"
607 IF (ionode) rand = rng_stream%next()
608 CALL group%bcast(rand, source)
610 IF (nboxes == 2)
THEN
611 IF (rand < 0.1e0_dp)
THEN
621 IF (ionode) rand = rng_stream%next()
622 CALL group%bcast(rand, source)
623 molecule_type_swap = 0
624 DO imol_type = 1, nmol_types
625 IF (rand < pmavbmc_mol(imol_type))
THEN
626 molecule_type_swap = imol_type
630 IF (molecule_type_swap == 0)
THEN
631 cpabort(
'Did not choose a molecule type to swap...check AVBMC input')
636 IF (sum(nchains(:, box_number)) <= 1)
THEN
638 moves(molecule_type_swap, box_number)%moves%empty_avbmc = &
639 moves(molecule_type_swap, box_number)%moves%empty_avbmc + 1
645 start_atom_swap, idum, jdum, rng_stream, &
646 box=box_number, molecule_type_old=molecule_type_swap)
651 start_atom_target, idum, molecule_type_target, &
652 rng_stream, box=box_number)
653 IF (start_atom_swap /= start_atom_target)
THEN
654 start_atom_target = start_atom_target + &
655 avbmc_atom(molecule_type_target) - 1
662 rand = rng_stream%next()
665 CALL group%bcast(start_atom_swap, source)
666 CALL group%bcast(box_number, source)
667 CALL group%bcast(start_atom_target, source)
668 CALL group%bcast(rand, source)
670 IF (rand < pbias(molecule_type_swap))
THEN
671 move_type_avbmc =
'in'
673 move_type_avbmc =
'out'
677 force_env(box_number)%force_env, &
678 bias_env(box_number)%force_env, &
679 moves(molecule_type_swap, box_number)%moves, &
680 energy_check(box_number), &
681 r_old(:, :, box_number), old_energy(box_number), &
682 start_atom_swap, start_atom_target, molecule_type_swap, &
683 box_number, bias_energy(box_number), &
684 last_bias_energy(box_number), &
685 move_type_avbmc, rng_stream)
691 IF (mod(nnstep, iprint) == 0 .AND. (iw > 0))
THEN
692 WRITE (iw, *)
"Attempting an inner move"
698 IF (ionode) rand = rng_stream%next()
699 CALL group%bcast(rand, source)
700 IF (rand < pmtraion)
THEN
703 IF (ionode) rand = rng_stream%next()
704 CALL group%bcast(rand, source)
705 IF (nboxes == 2)
THEN
706 IF (rand < 0.75e0_dp)
THEN
716 IF (ionode) rand = rng_stream%next()
717 CALL group%bcast(rand, source)
719 DO imol_type = 1, nmol_types
720 IF (rand < pmtraion_mol(imol_type))
THEN
721 molecule_type = imol_type
725 IF (molecule_type == 0)
CALL cp_abort( &
727 'Did not choose a molecule type to conf change...PMTRAION_MOL should not be all 0.0')
731 IF (nchains(molecule_type, box_number) == 0)
THEN
733 moves(molecule_type, box_number)%moves%empty_conf = &
734 moves(molecule_type, box_number)%moves%empty_conf + 1
741 box=box_number, molecule_type_old=molecule_type)
744 rand = rng_stream%next()
746 CALL group%bcast(rand, source)
747 CALL group%bcast(start_atom, source)
748 CALL group%bcast(box_number, source)
749 CALL group%bcast(molecule_type, source)
752 IF (rand < conf_prob(1, molecule_type))
THEN
754 ELSE IF (rand < (conf_prob(1, molecule_type) + &
755 conf_prob(2, molecule_type)))
THEN
758 move_type =
'dihedral'
760 box_flag(box_number) = 1
762 force_env(box_number)%force_env, &
763 bias_env(box_number)%force_env, &
764 moves(molecule_type, box_number)%moves, &
765 move_updates(molecule_type, box_number)%moves, &
766 start_atom, molecule_type, box_number, &
767 bias_energy(box_number), &
768 move_type, lreject, rng_stream)
771 ELSE IF (rand < pmtrans)
THEN
774 IF (ionode) rand = rng_stream%next()
775 CALL group%bcast(rand, source)
777 DO imol_type = 1, nmol_types
778 IF (rand < pmtrans_mol(imol_type))
THEN
779 molecule_type = imol_type
783 IF (molecule_type == 0)
CALL cp_abort( &
785 'Did not choose a molecule type to translate...PMTRANS_MOL should not be all 0.0')
790 start_atom, box_number, idum, rng_stream, &
791 molecule_type_old=molecule_type)
793 CALL group%bcast(start_atom, source)
794 CALL group%bcast(box_number, source)
795 box_flag(box_number) = 1
797 force_env(box_number)%force_env, &
798 bias_env(box_number)%force_env, &
799 moves(molecule_type, box_number)%moves, &
800 move_updates(molecule_type, box_number)%moves, &
801 start_atom, box_number, bias_energy(box_number), &
802 molecule_type, lreject, rng_stream)
804 ELSE IF (rand < pmcltrans)
THEN
807 IF (ionode) rand = rng_stream%next()
808 CALL group%bcast(rand, source)
811 IF (rand <= pmclus_box(ibox))
THEN
816 box_flag(box_number) = 1
818 force_env(box_number)%force_env, &
819 bias_env(box_number)%force_env, &
820 moves(1, box_number)%moves, &
821 move_updates(1, box_number)%moves, &
822 box_number, bias_energy(box_number), &
828 IF (ionode) rand = rng_stream%next()
829 CALL group%bcast(rand, source)
831 DO imol_type = 1, nmol_types
832 IF (rand < pmrot_mol(imol_type))
THEN
833 molecule_type = imol_type
837 IF (molecule_type == 0)
CALL cp_abort( &
839 'Did not choose a molecule type to rotate...PMROT_MOL should not be all 0.0')
843 start_atom, box_number, idum, rng_stream, &
844 molecule_type_old=molecule_type)
846 CALL group%bcast(start_atom, source)
847 CALL group%bcast(box_number, source)
848 box_flag(box_number) = 1
850 force_env(box_number)%force_env, &
851 bias_env(box_number)%force_env, &
852 moves(molecule_type, box_number)%moves, &
853 move_updates(molecule_type, box_number)%moves, &
854 box_number, start_atom, &
855 molecule_type, bias_energy(box_number), &
864 moves, lreject, move_updates, energy_check(:), r_old(:, :, :), &
865 nnstep, old_energy(:), bias_energy(:), last_bias_energy(:), &
866 nboxes, box_flag(:), oldsys, particles_old, &
867 rng_stream, unit_conv)
875 subsys=oldsys(ibox)%subsys, cell=cell(ibox)%cell)
876 CALL get_cell(cell(ibox)%cell, abc=abc(:, ibox))
878 particles=particles_old(ibox)%list)
883 IF (mod(nnstep, iprint) == 0)
THEN
884 WRITE (com_ene, *) nnstep, old_energy(1:nboxes)
889 WRITE (com_mol, *) nnstep, nchains(:, ibox)
892 DO itype = 1, nmol_types
894 nnstep, move_unit(ibox))
899 nchains(:, ibox), force_env(ibox)%force_env)
902 WRITE (cell_unit, *) nnstep, abc(1:3, ibox)*
angstrom
905 WRITE (cbox,
'(I4)') ibox
906 WRITE (cstep,
'(I8)') nnstep
907 IF (sum(nchains(:, ibox)) == 0)
THEN
908 WRITE (com_crd, *)
' 0'
909 WRITE (com_crd, *)
'BOX '//trim(adjustl(cbox))// &
910 ', STEP '//trim(adjustl(cstep))
913 particles_old(ibox)%list%els, &
915 'BOX '//trim(adjustl(cbox))// &
916 ', STEP '//trim(adjustl(cstep)), &
924 averages(ibox)%averages%ave_energy = &
925 averages(ibox)%averages%ave_energy*real(nnstep - &
926 nstart - 1,
dp)/real(nnstep - nstart,
dp) + &
927 old_energy(ibox)/real(nnstep - nstart,
dp)
928 averages(ibox)%averages%molecules = &
929 averages(ibox)%averages%molecules*real(nnstep - &
930 nstart - 1,
dp)/real(nnstep - nstart,
dp) + &
931 REAL(sum(nchains(:, ibox)),
dp)/
REAL(nnstep - nstart,
dp)
932 averages(ibox)%averages%ave_volume = &
933 averages(ibox)%averages%ave_volume* &
934 REAL(nnstep - nstart - 1,
dp)/
REAL(nnstep - nstart, dp) + &
935 abc(1, ibox)*abc(2, ibox)*abc(3, ibox)/ &
936 REAL(nnstep - nstart,
dp)
960 IF (should_stop)
EXIT
964 IF (mod(nnstep - nstart, iuptrans) == 0)
THEN
965 DO itype = 1, nmol_types
967 move_updates(itype, ibox)%moves, itype, &
968 "trans", nnstep, ionode)
972 IF (mod(nnstep - nstart, iupvolume) == 0)
THEN
974 move_updates(1, ibox)%moves, 1337, &
975 "volume", nnstep, ionode)
983 IF (sum(nchains(:, ibox)) /= 0)
THEN
985 DO jbox = 1, ibox - 1
986 start_mol = start_mol + sum(nchains(:, jbox))
988 end_mol = start_mol + sum(nchains(:, ibox)) - 1
990 nchains(:, ibox), nunits, loverlap, &
991 mol_type(start_mol:end_mol))
993 IF (iw > 0)
WRITE (iw, *) nnstep
994 cpabort(
'coordinate overlap at the end of the above step')
998 ALLOCATE (r_temp(1:3, 1:nunits_tot(ibox)))
1000 DO iunit = 1, nunits_tot(ibox)
1001 r_temp(1:3, iunit) = &
1002 particles_old(ibox)%list%els(iunit)%r(1:3)
1006 sum(nchains(:, ibox)), mol_type(start_mol:end_mol), &
1007 mass, nunits, abc(1:3, ibox))
1010 DO iunit = 1, nunits_tot(ibox)
1011 r_old(1:3, iunit, ibox) = r_temp(1:3, iunit)
1012 particles_old(ibox)%list%els(iunit)%r(1:3) = &
1021 particles=particles_bias)
1023 DO iunit = 1, nunits_tot(ibox)
1024 particles_bias%els(iunit)%r(1:3) = &
1036 IF (debug_this_module)
THEN
1038 IF (sum(nchains(:, ibox)) /= 0)
THEN
1042 potential_energy=test_energy)
1044 test_energy = 0.0e0_dp
1047 IF (abs(initial_energy(ibox) + energy_check(ibox) - &
1048 test_energy) > 0.0000001e0_dp)
THEN
1050 WRITE (iw, *)
'!!!!!!! We have an energy problem. !!!!!!!!'
1051 WRITE (iw,
'(A,T64,F16.10)')
'Final Energy = ', test_energy
1052 WRITE (iw,
'(A,T64,F16.10)')
'Initial Energy+energy_check=', &
1053 initial_energy(ibox) + energy_check(ibox)
1054 WRITE (iw, *)
'Box ', ibox
1055 WRITE (iw, *)
'nchains ', nchains(:, ibox)
1057 cpabort(
'!!!!!!! We have an energy problem. !!!!!!!!')
1067 nchains(:, ibox), force_env(ibox)%force_env)
1073 IF (sum(nchains(:, ibox)) /= 0)
THEN
1077 potential_energy=final_energy(ibox))
1079 final_energy(ibox) = 0.0e0_dp
1087 IF (ionode .OR. (iw > 0))
THEN
1089 WRITE (com_ene, *)
'Final Energies: ', &
1090 final_energy(1:nboxes)
1093 WRITE (cbox,
'(I4)') ibox
1094 IF (sum(nchains(:, ibox)) == 0)
THEN
1095 WRITE (com_crd, *)
' 0'
1096 WRITE (com_crd, *)
'BOX '//trim(adjustl(cbox))
1099 particles_old(ibox)%list%els, &
1101 'FINAL BOX '//trim(adjustl(cbox)), unit_conv=unit_conv)
1106 '------------------------------------------------'
1107 WRITE (iw,
'(A,I1,A)') &
1111 '------------------------------------------------'
1112 test_moves => moves(:, ibox)
1114 iw, energy_check(ibox), &
1115 initial_energy(ibox), final_energy(ibox), &
1116 averages(ibox)%averages)
1135 mc_par=mc_par(ibox)%mc_par, &
1136 force_env=force_env(ibox)%force_env)
1139 DO itype = 1, nmol_types
1146 DEALLOCATE (pmhmc_box)
1147 DEALLOCATE (pmvol_box)
1148 DEALLOCATE (pmclus_box)
1150 DEALLOCATE (force_env)
1151 DEALLOCATE (bias_env)
1153 DEALLOCATE (particles_old)
1155 DEALLOCATE (averages)
1157 DEALLOCATE (move_updates)
1161 CALL timestop(handle)
1186 INTEGER :: current_division, end_atom, ibin, idivision, iparticle, iprint, itemp, iunit, &
1187 ivirial, iw, nbins, nchain_total, nintegral_divisions, nmol_types, nvirial, &
1188 nvirial_temps, source, start_atom
1189 INTEGER,
DIMENSION(:),
POINTER :: mol_type, nunits, nunits_tot
1190 INTEGER,
DIMENSION(:, :),
POINTER :: nchains
1191 LOGICAL :: ionode, loverlap
1192 REAL(
dp),
DIMENSION(:),
POINTER :: beta, virial_cutoffs, virial_stepsize, &
1194 REAL(
dp),
DIMENSION(:, :),
POINTER :: mass, mayer, r_old
1195 REAL(kind=
dp) :: ave_virial, current_value, distance, exp_max_val, exp_min_val, exponent, &
1196 integral, previous_value, square_value, trial_energy, triangle_value
1197 REAL(kind=
dp),
DIMENSION(1:3) :: abc, center_of_mass
1203 DIMENSION(:),
POINTER :: mc_par
1211 nintegral_divisions = 3
1212 ALLOCATE (virial_cutoffs(1:nintegral_divisions))
1213 ALLOCATE (virial_stepsize(1:nintegral_divisions))
1214 virial_cutoffs(1) = 8.0
1215 virial_cutoffs(2) = 13.0
1216 virial_cutoffs(3) = 22.0
1217 virial_stepsize(1) = 0.04
1218 virial_stepsize(2) = 0.1
1219 virial_stepsize(3) = 0.2
1221 nbins = ceiling(virial_cutoffs(1)/virial_stepsize(1) + (virial_cutoffs(2) - virial_cutoffs(1))/ &
1222 virial_stepsize(2) + (virial_cutoffs(3) - virial_cutoffs(2))/virial_stepsize(3))
1228 ALLOCATE (force_env(1:1))
1229 ALLOCATE (cell(1:1))
1230 ALLOCATE (particles(1:1))
1231 ALLOCATE (subsys(1:1))
1232 ALLOCATE (mc_par(1:1))
1235 mc_par=mc_par(1)%mc_par, &
1236 force_env=force_env(1)%force_env)
1240 exp_max_val=exp_max_val, &
1241 exp_min_val=exp_min_val, nvirial=nvirial, &
1242 ionode=ionode, source=source, group=group, &
1243 mc_molecule_info=mc_molecule_info, virial_temps=virial_temps)
1248 WRITE (iw, *)
'Beginning the calculation of the second virial coefficient'
1255 nchains=nchains, nmol_types=nmol_types, nunits_tot=nunits_tot, &
1256 mol_type=mol_type, nchain_total=nchain_total, nunits=nunits, &
1259 nvirial_temps =
SIZE(virial_temps)
1260 ALLOCATE (beta(1:nvirial_temps))
1262 DO itemp = 1, nvirial_temps
1268 subsys=subsys(1)%subsys, cell=cell(1)%cell)
1269 CALL get_cell(cell(1)%cell, abc=abc(:))
1271 particles=particles(1)%list)
1274 IF (abc(1) /= abc(2) .OR. abc(2) /= abc(3))
THEN
1275 cpabort(
'The box needs to be cubic for a virial calculation (it is easiest).')
1277 IF (virial_cutoffs(nintegral_divisions) > abc(1)/2.0e0_dp)
THEN
1279 WRITE (iw, *)
"Box length ", abc(1)*
angstrom,
" virial cutoff ", &
1280 virial_cutoffs(nintegral_divisions)*
angstrom
1282 cpabort(
'You need a bigger box to deal with this virial cutoff (see above).')
1286 ALLOCATE (r_old(1:3, 1:nunits_tot(1)))
1288 DO iparticle = 1, nunits_tot(1)
1289 r_old(1:3, iparticle) = &
1290 particles(1)%list%els(iparticle)%r(1:3)
1295 end_atom = nunits(mol_type(1))
1297 center_of_mass(:), mass(1:nunits(mol_type(1)), mol_type(1)))
1298 DO iunit = start_atom, end_atom
1299 r_old(:, iunit) = r_old(:, iunit) - center_of_mass(:)
1302 DO iparticle = start_atom, end_atom
1303 particles(1)%list%els(iparticle)%r(1:3) = r_old(1:3, iparticle)
1307 iprint = floor(real(nvirial, kind=
dp)/100.0_dp)
1308 IF (iprint == 0) iprint = 1
1312 ALLOCATE (mayer(1:nvirial_temps, 1:nbins))
1314 mayer(:, :) = 0.0_dp
1317 DO ivirial = 1, nvirial
1320 start_atom = nunits(mol_type(1)) + 1
1321 end_atom = nunits_tot(1)
1323 center_of_mass(:), mass(1:nunits(mol_type(2)), mol_type(2)))
1324 DO iunit = start_atom, end_atom
1325 r_old(:, iunit) = r_old(:, iunit) - center_of_mass(:)
1332 mass(1:nunits(mol_type(2)), mol_type(2)), &
1333 nunits(mol_type(2)), rng_stream)
1335 CALL group%bcast(r_old(:, :), source)
1341 current_division = 0
1342 DO idivision = 1, nintegral_divisions
1343 IF (distance < virial_cutoffs(idivision) - virial_stepsize(idivision)/2.0e0_dp)
THEN
1344 current_division = idivision
1348 IF (current_division == 0)
EXIT
1349 distance = distance + virial_stepsize(current_division)
1352 DO iparticle = start_atom, end_atom
1353 particles(1)%list%els(iparticle)%r(1) = r_old(1, iparticle) + distance
1354 particles(1)%list%els(iparticle)%r(2) = r_old(2, iparticle)
1355 particles(1)%list%els(iparticle)%r(3) = r_old(3, iparticle)
1359 CALL check_for_overlap(force_env(1)%force_env, nchains(:, 1), nunits, loverlap, mol_type)
1364 DO itemp = 1, nvirial_temps
1365 mayer(itemp, ibin) = mayer(itemp, ibin) - 1.0_dp
1371 potential_energy=trial_energy)
1373 DO itemp = 1, nvirial_temps
1375 exponent = -beta(itemp)*trial_energy
1377 IF (exponent > exp_max_val)
THEN
1378 exponent = exp_max_val
1379 ELSE IF (exponent < exp_min_val)
THEN
1380 exponent = exp_min_val
1382 mayer(itemp, ibin) = mayer(itemp, ibin) + exp(exponent) - 1.0_dp
1390 IF (mod(ivirial, iprint) == 0)
THEN
1391 WRITE (iw,
'(A,I6,A,I6)')
' Done with config ', ivirial,
' out of ', nvirial
1397 mayer(:, :) = mayer(:, :)/real(nvirial,
dp)
1399 DO itemp = 1, nvirial_temps
1401 previous_value = 0.0_dp
1405 current_division = 0
1406 DO idivision = 1, nintegral_divisions
1407 IF (distance < virial_cutoffs(idivision) - virial_stepsize(idivision)/2.0e0_dp)
THEN
1408 current_division = idivision
1412 IF (current_division == 0)
EXIT
1413 distance = distance + virial_stepsize(current_division)
1417 current_value = mayer(itemp, ibin)*distance**2
1418 square_value = previous_value*virial_stepsize(current_division)
1421 triangle_value = 0.5e0_dp*((current_value - previous_value)*virial_stepsize(current_division))
1423 integral = integral + square_value + triangle_value
1424 previous_value = current_value
1429 ave_virial = -2.0e0_dp*
pi*integral
1436 WRITE (iw, *)
'*********************************************************************'
1437 WRITE (iw,
'(A,F12.6,A)')
' *** Temperature = ', virial_temps(itemp), &
1439 WRITE (iw, *)
'*** ***'
1440 WRITE (iw,
'(A,E12.6,A)')
' *** B2(T) = ', ave_virial, &
1442 WRITE (iw, *)
'*********************************************************************'
1450 DEALLOCATE (force_env)
1451 DEALLOCATE (particles)
1453 DEALLOCATE (virial_cutoffs)
1454 DEALLOCATE (virial_stepsize)