@@ -259,7 +259,8 @@ subroutine AllocateAtomArrays()
259259 allocate (reservoir% mol_com(3 , nb% type_residue, NB_MAX_MOLECULE))
260260 allocate (reservoir% site_offset(3 , nb% type_residue, NB_MAX_MOLECULE, nb% max_atom_in_residue))
261261 allocate (reservoir% num_residues(nb% type_residue))
262- allocate (res% mass_residue(nb% type_residue))
262+ allocate (res% mass(nb% type_residue))
263+ allocate (res% lambda(nb% type_residue))
263264
264265 ! Allocate parameter arrays
265266 allocate (coeff% sigma(nb% type_residue, nb% type_residue,&
@@ -270,6 +271,7 @@ subroutine AllocateAtomArrays()
270271 allocate (res% types_2d(nb% type_residue, nb% max_type_per_residue))
271272 allocate (res% names_2d(nb% type_residue, nb% max_type_per_residue))
272273 allocate (input% fugacity(nb% type_residue))
274+ allocate (input% chemical_potential(nb% type_residue))
273275 allocate (nb% types_per_residue(nb% type_residue))
274276 allocate (nb% atom_in_residue(nb% type_residue))
275277 allocate (nb% bonds_per_residue(nb% type_residue))
@@ -325,6 +327,7 @@ subroutine ParseInputFile(INFILE)
325327 logical :: has_translation_step, has_rotation_step, has_recalibrate
326328 logical :: has_translation_proba, has_rotation_proba
327329 logical :: has_insertdel_proba, has_swap_proba, has_widom_proba
330+ logical :: has_fugacity, has_chemical_potential
328331
329332 has_nb_block = .false.
330333 has_nb_step = .false.
@@ -347,6 +350,8 @@ subroutine ParseInputFile(INFILE)
347350
348351 ! Initialize all fugacities to -1.0 (indicating unset)
349352 input% fugacity(:) = - one
353+ ! Initialize all chemical_potential to 0.0 (indicating unset)
354+ input% chemical_potential(:) = zero
350355
351356 do
352357 read (INFILE, ' (A)' , IOSTAT= ios) line
@@ -379,7 +384,7 @@ subroutine ParseInputFile(INFILE)
379384 read (rest_line, * , iostat= ios) val_real
380385 if (ios /= 0 ) error stop " Error reading temperature"
381386 if (val_real <= zero) error stop " Invalid temperature: must be > 0"
382- input% temp_K = val_real
387+ input% temperature = val_real
383388 has_temp = .true.
384389
385390 case (" seed" )
@@ -473,7 +478,7 @@ subroutine ParseInputFile(INFILE)
473478 end select
474479
475480 ! ===============================
476- ! Residue parsing (types, names, fugacity, nb-atoms)
481+ ! Residue parsing (types, names, fugacity, chemical potential nb-atoms)
477482 ! ===============================
478483 if (in_residue_block) then
479484
@@ -520,6 +525,11 @@ subroutine ParseInputFile(INFILE)
520525 read (rest_line, * , iostat= ios) val_real
521526 input% fugacity(nb% type_residue + 1 ) = val_real
522527
528+ ! Check if the line specifies the chemical potential
529+ else if (trim (token) == ' chemical_potential' ) then
530+ read (rest_line, * , iostat= ios) val_real
531+ input% chemical_potential(nb% type_residue + 1 ) = val_real
532+
523533 ! Check if the line specifies the number of atoms
524534 else if (trim (token) == ' nb-atoms' ) then
525535 read (rest_line, * , iostat= ios) val_int
@@ -571,12 +581,24 @@ subroutine ParseInputFile(INFILE)
571581
572582 ! Validate fugacity for active residues
573583 do val_int = 1 , nb% type_residue
574- if (input% is_active(val_int) == 1 ) then
575- if (input% fugacity(val_int) < zero) then
576- call AbortRun(" Fugacity not provided or invalid for active residue: " &
577- // trim (res% names_1d(val_int)))
578- end if
584+
585+ if (input% is_active(val_int) == 0 ) cycle
586+
587+ has_fugacity = (input% fugacity(val_int) >= zero)
588+ has_chemical_potential = (input% chemical_potential(val_int) < zero)
589+
590+ ! Rule 1: at least one must be provided
591+ if (.not. (has_fugacity .or. has_chemical_potential)) then
592+ call AbortRun(" Neither fugacity nor chemical potential provided for active residue: " // &
593+ trim (res% names_1d(val_int)))
594+ end if
595+
596+ ! Rule 2: cannot both be provided
597+ if (has_fugacity .and. has_chemical_potential) then
598+ call AbortRun(" Both fugacity and chemical potential were specified for active residue: " // &
599+ trim (res% names_1d(val_int)))
579600 end if
601+
580602 end do
581603
582604 ! === Validation of required parameters ===
@@ -628,7 +650,7 @@ subroutine SortResidues()
628650 integer , allocatable :: keys(:), order(:)
629651 character (len= 10 ), allocatable :: tmp_names_1d(:)
630652 integer , allocatable :: tmp_is_active(:), tmp_atom_in_residue(:), tmp_types_per_residue(:)
631- real (real64), allocatable :: tmp_fugacity(:)
653+ real (real64), allocatable :: tmp_fugacity(:), tmp_chemical_potential(:)
632654 integer , allocatable :: tmp_types_2d(:,:)
633655 character (len= 10 ), allocatable :: tmp_names_2d(:,:)
634656
@@ -640,6 +662,7 @@ subroutine SortResidues()
640662 allocate (tmp_names_1d(n))
641663 allocate (tmp_is_active(n))
642664 allocate (tmp_fugacity(n))
665+ allocate (tmp_chemical_potential(n))
643666 allocate (tmp_atom_in_residue(n))
644667 allocate (tmp_types_per_residue(n))
645668 allocate (tmp_types_2d(size (res% types_2d,1 ), size (res% types_2d,2 )))
@@ -670,6 +693,7 @@ subroutine SortResidues()
670693 tmp_names_1d(i) = res% names_1d(k)
671694 tmp_is_active(i) = input% is_active(k)
672695 tmp_fugacity(i) = input% fugacity(k)
696+ tmp_chemical_potential(i) = input% chemical_potential(k)
673697 tmp_atom_in_residue(i) = nb% atom_in_residue(k)
674698 tmp_types_per_residue(i) = nb% types_per_residue(k)
675699 tmp_types_2d(i,:) = res% types_2d(k,:)
@@ -680,13 +704,14 @@ subroutine SortResidues()
680704 res% names_1d = tmp_names_1d
681705 input% is_active = tmp_is_active
682706 input% fugacity = tmp_fugacity
707+ input% chemical_potential = tmp_chemical_potential
683708 nb% atom_in_residue = tmp_atom_in_residue
684709 nb% types_per_residue = tmp_types_per_residue
685710 res% types_2d = tmp_types_2d
686711 res% names_2d = tmp_names_2d
687712
688713 ! Deallocate temporary arrays
689- deallocate (keys, order, tmp_names_1d, tmp_is_active, tmp_fugacity, &
714+ deallocate (keys, order, tmp_names_1d, tmp_is_active, tmp_fugacity, tmp_chemical_potential, &
690715 tmp_atom_in_residue, tmp_types_per_residue, tmp_types_2d, tmp_names_2d)
691716
692717 end subroutine SortResidues
0 commit comments