-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force on external point charge or external electric field by electron density? #488
Comments
The API already supports setting point charges via Lines 187 to 199 in 0245411
The gradient will also be calculated but cannot be retrieved from the API since there is no call for this yet. Some notes on the current state of the external point charges, in case anyone want to give it a try. The external point charges are wrapped in a derived type here inside the calculator object Lines 73 to 74 in 0245411
which has a field for the gradients which will be populated after the singlepoint calculation Line 30 in 0245411
The only access via the API to the external point charge field is its deconstructor here Lines 502 to 532 in 0245411
But the logic to retrieve the gradient in a getter function would be quite similar. |
Hi,
and in the xtb.h file
Best Edit: Obvious mistake in the header file, corrected |
Close, but the C-API export doesn't match the provided header. Be careful to check for the existence of the elements you are accessing, otherwise the application will segfault. Here is something that might work (I didn't compile nor test it with !> Retrieve point charge gradient
subroutine getPCGradient_api(venv, vcalc, gradient) &
& bind(C, name="xtb_getPCGradient")
character(len=*), parameter :: source = 'xtb_getPCGradient'
type(c_ptr), value :: venv
type(VEnvironment), pointer :: env
type(c_ptr), value :: vcalc
type(VCalculator), pointer :: calc
real(c_double), intent(inout) :: gradient(*)
if (c_associated(venv)) then
call c_f_pointer(venv, env)
call checkGlobalEnv
if (.not.c_associated(vcalc)) then
call env%ptr%error("Singlepoint calculator is not allocated", source)
return
end if
call c_f_pointer(vcalc, calc)
if (.not.allocated(calc%ptr)) then
call env%ptr%error("Singlepoint calculator is not initialized", source)
return
end if
select type(xtb => calc%ptr)
type is(TxTBCalculator)
if (.not.allocated(xtb%pcem%grd)) then
call env%ptr%error("Point charge gradient not available due to missing point charge data", source)
return
end if
gradient(1:size(xtb%pcem%grd)) = reshape(xtb%pcem%grd, [size(xtb%pcem%grd)])
class default
call env%ptr%error("Calculator does not provide point charge gradient", source)
end select
end if
end subroutine releaseExternalCharges_api Which provides the C-API extern XTB_API_ENTRY void XTB_API_CALL
xtb_getPCGradient(xtb_TEnvironment /* env */,
xtb_TCalculator /* calc */,
double* /* gradient [n][3] */); |
The code snippets are actually tested (without segfaults), however, I did not copy pasted the complete changes of the files to this thread. Anyway, I guess the pointers you gave in your first response (in addition with your last comment) are sufficient to make the required changes. Edit: You are obviously right, I pasted the wrong version
Best |
Is your feature request related to a problem? Please describe.
I am trying to write a QM/MM interface of xtb and charmm MD package, but I cannot find a proper way to calculated the force on MM point charge.
Describe the solution you'd like
If the force on MM point charge is given directly is better.
Another way is to give the electric field on each point charge site, so the force can be calculated easily.
Hope this can be in the C API.
Describe alternatives you've considered
Using the cube file to calculate the force on each point can also work, I just want to know if there is a better way to go.
The text was updated successfully, but these errors were encountered: