Skip to content

Commit

Permalink
overload PDBTools.center_of_mass to avoid conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Apr 9, 2024
1 parent 94eff54 commit 178fab9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ EasyFit = "0.6.6"
LaTeXStrings = "1.3"
LinearAlgebra = "1.9"
OffsetArrays = "1.13"
PDBTools = "1.2"
PDBTools = "1.5.1"
Plots = "1.39"
ProgressMeter = "1.10"
Reexport = "1.2.2"
Expand Down
1 change: 1 addition & 0 deletions src/MolSimToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export distances
export align, align!, rmsd, rmsd_matrix
export intermittent_correlation
export bulk_coordination
export center_of_mass

# Testing module
include("./Testing.jl")
Expand Down
11 changes: 1 addition & 10 deletions src/miscelaneous_functions/center_of_mass.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export center_of_mass

"""
center_of_mass(
indices::AbstractVector{Int};
Expand Down Expand Up @@ -36,7 +34,7 @@ julia> cm = center_of_mass(protein_indices, simulation, coor)
```
"""
function center_of_mass(
function PDBTools.center_of_mass(
indices::AbstractVector{Int},
simulation::Simulation,
p::FramePositions;
Expand Down Expand Up @@ -66,10 +64,3 @@ end
[-3.7290442807974906, -1.5339226637687564, 1.960640754560446]
end

center_of_mass(x::AbstractVector{<:AbstractVector}, ::Nothing) = sum(x) / length(x)

center_of_mass(x::AbstractVector{<:AbstractVector}, mass::AbstractVector) =
sum(x[i] * mass[i] for i in eachindex(x, mass)) / sum(mass)

center_of_mass(atoms::AbstractVector{<:PDBTools.Atom}) =
sum(PDBTools.coor(atom) * atomic_mass(atom) for atom in atoms) / sum(atomic_mass, atoms)
8 changes: 6 additions & 2 deletions src/procrustes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using LinearAlgebra: eigvecs
using StaticArrays: SVector, MMatrix, SMatrix

_center_of_mass(x::AbstractVector{<:AbstractVector}, ::Nothing) = sum(x) / length(x)
_center_of_mass(x::AbstractVector{<:AbstractVector}, mass::AbstractVector) =
sum(x[i] * mass[i] for i in eachindex(x, mass)) / sum(mass)

"""
align(x, y; mass = nothing)
align!(x, y; mass = nothing)
Expand Down Expand Up @@ -40,8 +44,8 @@ function align!(
length(x) == length(y) || throw(DimensionMismatch("x and y must have the same length"))
(length(x[1]) != 3 || length(x[2]) != 3) && throw(DimensionMismatch("x and y must be 3D vectors"))

cmx = center_of_mass(x, mass)
cmy = center_of_mass(y, mass)
cmx = _center_of_mass(x, mass)
cmy = _center_of_mass(y, mass)
for i in eachindex(x, y)
x[i] -= cmx
y[i] -= cmy
Expand Down

4 comments on commit 178fab9

@lmiq
Copy link
Member Author

@lmiq lmiq commented on 178fab9 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • overload PDBTools.center_of_mass to avoid conflicts

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104558

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.12.7 -m "<description of version>" 178fab9c37df1e8d31aa03e2a4c55480267c4886
git push origin v1.12.7

@lmiq
Copy link
Member Author

@lmiq lmiq commented on 178fab9 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • overload PDBTools.center_of_mass to avoid conflicts

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 1.12.7 already exists

Please sign in to comment.