@@ -14,11 +14,11 @@ module ewald_phase
1414 ! Saves the current Fourier-space phase factors and reciprocal amplitudes
1515 ! for a specific molecule or residue, enabling rollback after a rejected move.
1616 !- -------------------------------------------------------------------
17- subroutine save_single_mol_fourier_terms (residue_type , molecule_index , symmetrize_x )
17+ subroutine save_single_mol_fourier_terms (res_type , mol_index , symmetrize_x )
1818
1919 ! Input arguments
20- integer , intent (in ) :: residue_type ! Residue type identifier
21- integer , intent (in ) :: molecule_index ! Molecule index to save
20+ integer , intent (in ) :: res_type ! Residue type identifier
21+ integer , intent (in ) :: mol_index ! Molecule index to save
2222 logical , intent (in ), optional :: symmetrize_x ! Whether to save negative kx
2323
2424 ! Local variables
@@ -32,24 +32,27 @@ subroutine save_single_mol_fourier_terms(residue_type, molecule_index, symmetriz
3232 do_sym = .false.
3333 if (present (symmetrize_x)) do_sym = symmetrize_x
3434
35+ ! Ensure that the routine deals with guest, not host
36+ if (res% role(res_type) == TYPE_HOST) call abort_run(" Inconsistence in fourier routine" )
37+
3538 !- ---------------------------------------------------------
3639 ! Save per-atom Fourier phase factors (IKX, IKY, IKZ)
3740 !- ---------------------------------------------------------
38- do atom_index = 1 , res% atom(residue_type )
41+ do atom_index = 1 , res% atom(res_type )
3942
4043 do dim = 1 , 3
4144
4245 do k_idx = 0 , ewald% param% kmax(dim)
4346
4447 ! Positive k
4548 ewald% phase% factor_old(dim, atom_index, k_idx) = &
46- ewald% phase% factor (dim, residue_type, molecule_index , atom_index, k_idx)
49+ ewald% phase% factor_guest (dim, res_type, mol_index , atom_index, k_idx)
4750
4851 ! Negative k (only if non-zero)
4952 if (k_idx /= 0 ) then
5053 if (dim /= 1 .or. do_sym) then
5154 ewald% phase% factor_old(dim, atom_index, - k_idx) = &
52- ewald% phase% factor (dim, residue_type, molecule_index , atom_index, - k_idx)
55+ ewald% phase% factor_guest (dim, res_type, mol_index , atom_index, - k_idx)
5356 end if
5457 end if
5558
@@ -72,12 +75,12 @@ end subroutine save_single_mol_fourier_terms
7275 ! Restores previously saved Fourier-space phase factors and reciprocal
7376 ! amplitudes for a molecule or residue after a rejected move.
7477 !- -------------------------------------------------------------------
75- subroutine restore_single_mol_fourier (residue_type , molecule_index , symmetrize_x )
78+ subroutine restore_single_mol_fourier (res_type , mol_index , symmetrize_x )
7679
7780 ! Input arguments
78- integer , intent (in ) :: residue_type ! Residue type index
79- integer , intent (in ) :: molecule_index ! Molecule index to restore
80- logical , intent (in ), optional :: symmetrize_x ! Restore negative kx if true
81+ integer , intent (in ) :: res_type ! Residue type index
82+ integer , intent (in ) :: mol_index ! Molecule index to restore
83+ logical , intent (in ), optional :: symmetrize_x ! Restore negative kx if true
8184
8285 ! Local variables
8386 integer :: atom_index_1 ! Atom index
@@ -90,23 +93,24 @@ subroutine restore_single_mol_fourier(residue_type, molecule_index, symmetrize_x
9093 do_sym = .false.
9194 if (present (symmetrize_x)) do_sym = symmetrize_x
9295
93- !- ---------------------------------------------------------
96+ ! Ensure that the routine deals with guest, not host
97+ if (res% role(res_type) == TYPE_HOST) call abort_run(" Inconsistence in fourier routine" )
98+
9499 ! Restore per-atom Fourier phase factors (IKX, IKY, IKZ)
95- !- ---------------------------------------------------------
96- do atom_index_1 = 1 , res% atom(residue_type)
100+ do atom_index_1 = 1 , res% atom(res_type)
97101
98102 do dim = 1 , 3
99103
100104 do k_idx = 0 , ewald% param% kmax(dim)
101105
102106 ! Positive k
103- ewald% phase% factor (dim, residue_type, molecule_index , atom_index_1, k_idx) = &
107+ ewald% phase% factor_guest (dim, res_type, mol_index , atom_index_1, k_idx) = &
104108 ewald% phase% factor_old(dim, atom_index_1, k_idx)
105109
106110 ! Negative k
107111 if (k_idx /= 0 ) then
108112 if (dim /= 1 .or. do_sym) then
109- ewald% phase% factor (dim, residue_type, molecule_index , atom_index_1, - k_idx) = &
113+ ewald% phase% factor_guest (dim, res_type, mol_index , atom_index_1, - k_idx) = &
110114 ewald% phase% factor_old(dim, atom_index_1, - k_idx)
111115 end if
112116 end if
@@ -128,10 +132,10 @@ end subroutine restore_single_mol_fourier
128132 ! Replaces the Fourier-space phase factors of one molecule (`index_1`)
129133 ! with those from another molecule (`index_2`) of the same residue type.
130134 !- -------------------------------------------------------------------
131- subroutine replace_fourier_terms_single_mol (residue_type , index_1 , index_2 , symmetrize_x )
135+ subroutine replace_fourier_terms_single_mol (res_type , index_1 , index_2 , symmetrize_x )
132136
133137 ! Input arguments
134- integer , intent (in ) :: residue_type ! Residue type index
138+ integer , intent (in ) :: res_type ! Residue type index
135139 integer , intent (in ) :: index_1 ! Destination molecule index
136140 integer , intent (in ) :: index_2 ! Source molecule index
137141 logical , intent (in ), optional :: symmetrize_x ! Copy negative kx if true
@@ -146,22 +150,25 @@ subroutine replace_fourier_terms_single_mol(residue_type, index_1, index_2, symm
146150 do_sym = .false.
147151 if (present (symmetrize_x)) do_sym = symmetrize_x
148152
153+ ! Ensure that the routine deals with guest, not host
154+ if (res% role(res_type) == TYPE_HOST) call abort_run(" Inconsistence in fourier routine" )
155+
149156 ! Restore IKX, IKY, IKZ from backups
150- do atom_index_1 = 1 , res% atom(residue_type )
157+ do atom_index_1 = 1 , res% atom(res_type )
151158
152159 do dim = 1 , 3
153160
154161 do k_idx = 0 , ewald% param% kmax(dim)
155162
156163 ! Always copy positive (and zero) k
157- ewald% phase% factor (dim, residue_type , index_1, atom_index_1, k_idx) = &
158- ewald% phase% factor (dim, residue_type , index_2, atom_index_1, k_idx)
164+ ewald% phase% factor_guest (dim, res_type , index_1, atom_index_1, k_idx) = &
165+ ewald% phase% factor_guest (dim, res_type , index_2, atom_index_1, k_idx)
159166
160167 ! Copy negative k only when allowed (when d=1, only if symmetrize_x is true, or when d=2,3)
161168 if (k_idx /= 0 ) then
162169 if (dim /= 1 .or. do_sym) then
163- ewald% phase% factor (dim, residue_type , index_1, atom_index_1, - k_idx) = &
164- ewald% phase% factor (dim, residue_type , index_2, atom_index_1, - k_idx)
170+ ewald% phase% factor_guest (dim, res_type , index_1, atom_index_1, - k_idx) = &
171+ ewald% phase% factor_guest (dim, res_type , index_2, atom_index_1, - k_idx)
165172 end if
166173 end if
167174
@@ -178,17 +185,17 @@ end subroutine replace_fourier_terms_single_mol
178185 subroutine compute_all_fourier_terms ()
179186
180187 ! Local variables
181- integer :: residue_type
182- integer :: molecule_index
188+ integer :: res_type
189+ integer :: mol_index
183190
184191 ! Loop over all residue types
185- do residue_type = 1 , res% number
192+ do res_type = 1 , res% number
186193
187194 ! Loop over all molecules of this residue type
188- do molecule_index = 1 , primary% num% residues(residue_type )
195+ do mol_index = 1 , primary% num% residues(res_type )
189196
190197 ! Compute Fourier terms for a single molecule
191- call single_mol_fourier_terms(residue_type, molecule_index )
198+ call single_mol_fourier_terms(res_type, mol_index )
192199
193200 end do
194201 end do
@@ -230,11 +237,18 @@ subroutine single_mol_fourier_terms(res_type, mol_index)
230237 ! along each Cartesian direction. These factors will be used repeatedly
231238 ! in the reciprocal-space sum for the Ewald energy.
232239 do idim = 1 , 3
240+
233241 call compute_phase_factor(ewald% phase% axis(:), local_phase(idim), ewald% param% kmax(idim))
234- ewald% phase% factor(idim, res_type, mol_index, atom_index_1, &
235- - ewald% param% kmax(idim):ewald% param% kmax(idim)) = ewald% phase% axis(:)
236- end do
237242
243+ ! Differentiate between host and guest
244+ if (res% role(res_type) == TYPE_HOST) then
245+ ewald% phase% factor_host(idim, res_type, mol_index, atom_index_1, &
246+ - ewald% param% kmax(idim):ewald% param% kmax(idim)) = ewald% phase% axis(:)
247+ else if (res% role(res_type) == TYPE_GUEST) then
248+ ewald% phase% factor_guest(idim, res_type, mol_index, atom_index_1, &
249+ - ewald% param% kmax(idim):ewald% param% kmax(idim)) = ewald% phase% axis(:)
250+ end if
251+ end do
238252 end do
239253
240254 end subroutine single_mol_fourier_terms
0 commit comments