sergio-santos-group / ProtoSyn.jl

A Julia-based framework for molecular modelling
https://sergio-santos-group.github.io/ProtoSyn.jl/stable/
GNU Affero General Public License v3.0
58 stars 7 forks source link

Error when calculating forces #48

Closed zznidar closed 1 year ago

zznidar commented 1 year ago

Looking at the Example 4, I came across an error when calculating forces. It is thrown when running energy_function(pose, true) (actually, it seems the name of the keyworded argument has changed since the Example had been written, so I actually tried to run energy_function(pose, update_forces_overwrite=true)).

Although it seems to change the pose.state.f matrix, it throws ERROR: TypeError: in keyword argument v, expected Union{Nothing, Tuple{Float64, Float64, Float64}}, got a value of type SIMD.Vec{4, Float64}. This in turn prevents the steepest_descent from Example 6 from running.

Stack Trace ``` ERROR: TypeError: in keyword argument v, expected Union{Nothing, Tuple{Float64, Float64, Float64}}, got a value of type SIMD.Vec{4, Float64} Stacktrace: [1] macro expansion @ C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\Potentials\calculation_stage_simd.jl:67 [inlined] [2] macro expansion @ .\simdloop.jl:77 [inlined] [3] macro expansion @ C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\Potentials\calculation_stage_simd.jl:57 [inlined] [4] macro expansion @ .\simdloop.jl:77 [inlined] [5] macro expansion @ C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\Potentials\calculation_stage_simd.jl:53 [inlined] [6] resolve_calculation(#unused#::Type{ProtoSyn.SIMD_1}, pose::Pose{Topology}, potential::ProtoSyn.Calculators.var"#bump_potential_charges#29"{ProtoSyn.Calculators.var"#bump_potential_charges#28#30"{Float64, Float64}}, update_forces::Bool, verlet_list::Nothing, coords::Vector{Float64}, mask::Mask{Atom}, indexes::Vector{Int64}) @ ProtoSyn.Calculators C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\Potentials\calculation_stage_simd.jl:32 [7] resolve_selection(A::Type{ProtoSyn.SIMD_1}, pose::Pose{Topology}, potential::Function, update_forces::Bool, verlet_list::Nothing, selection::TrueSelection{ProtoSyn.Stateless, Atom}, mask::typeof(ProtoSyn.Calculators.get_intra_residue_mask)) @ ProtoSyn.Calculators C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\Potentials\selection_stage.jl:58 [8] apply_potential @ C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\Potentials\potentials.jl:17 [inlined] [9] calc_coulomb(::Type{ProtoSyn.SIMD_1}, pose::Pose{Topology}, selection::TrueSelection{ProtoSyn.Stateless, Atom}, update_forces::Bool; mask::typeof(ProtoSyn.Calculators.get_intra_residue_mask), vlist::Nothing, potential::ProtoSyn.Calculators.var"#bump_potential_charges#29"{ProtoSyn.Calculators.var"#bump_potential_charges#28#30"{Float64, Float64}}) @ ProtoSyn.Calculators.Electrostatics C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\electrostatics.jl:199 [10] (::ProtoSyn.Calculators.EnergyFunction)(pose::Pose{Topology}; update_forces_overwrite::Bool) @ ProtoSyn.Calculators C:\Users\Username\.julia\packages\ProtoSyn\Yx5Xy\src\Core\Calculators\energy_function.jl:223 [11] top-level scope @ c:\Users\Username\example4.jl:12 ```

I have tried Pkg adding SIMD, then also downgrading SIMD to 3.4.1 and later to 3.3.1, but none of this helped.

JosePereiraUA commented 1 year ago

Hey, thanks for the find. I usually use CUDA_2 acceleration mode, so haven't encountered this problem, which only occurs when using SIMD_1. I've fixed it in commit a3da8ca6878f245aebad5c1232ed14c023ec8a10. Note that, in ProtoSyn.jl's current version, long-range electrostatic interactions do not contribute to the force calculation (yet). Let me know if this is something you absolutely require (currently, long range interactions are generally considered as too weak to have any meaningful impact in force calculation). Check it out and feel free to give some feedback.

zznidar commented 1 year ago

Wonderful! After updating ProtoSyn#dev and ONNX to v0.2.1, the calculation of forces works, and Steepest Descent runs as well :) Thanks!