Skip to content

Commit

Permalink
support selection string input
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Sep 11, 2024
1 parent d990652 commit 4095020
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/miscelaneous_functions/most_representative_structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,39 @@ The process is repeated until the structure most similar to the average is the s
# Arguments
- `simulation::Simulation`: Simulation object.
- `atoms::Union{Nothing, AbstractVector{<:PDBTools.Atom}, AbstractVector{Int}}`: Atoms to consider in the calculation.
If `atoms` is `nothing`, the function will consider all alpha-carbons in proteins (`"protein and name CA"`).
- `atoms`: Atoms to consider in the calculation:
- `atoms` is `nothing`: the function will consider all alpha-carbons in proteins (`"protein and name CA"`).
- `atoms` is an `AbstractVector{<:PDBTools.Atom}`: the function will consider the atoms in the vector.
- `atoms` is an `AbstractVector{<:Int}`: the function will consider the atoms with the indices in the vector.
- `atoms` is a `String`: the function will consider the atoms selected by the string.
# Returns
- `imin::Int`: Index of the most representative structure.
- `rmsdmin::Float64`: RMSD of the most representative structure with respect to the average structure.
- Tuple `(Int, Float64)`, with:
- Index of the most representative structure.
- RMSD of the most representative structure with respect to the average structure.
# Example
```julia-repl
julia> using MolSimToolkit, MolSimToolkit.Testing
julia> using MolSimToolkit, MolSimToolkit.Testing, PDBTools
julia> simulation = Simulation(Testing.namd_pdb, Testing.namd_traj);
julia> most_representative_structure(simulation) # atoms == nothing (all alpha-carbons in proteins)
(4, 1.1681526249035976)
julia> most_representative_structure(simulation; atoms = "protein and name CA") # atoms is a String
(4, 1.1681526249035976)
julia> calphas = select(atoms(simulation), "name CA");
julia> most_representative_structure(simulation; atoms = calphas)
julia> most_representative_structure(simulation; atoms = calphas) # atoms is an AbstractVector{PDBTools.Atom}
(4, 1.1681526249035976)
julia> ica = PDBTools.index.(calphas)
julia> most_representative_structure(simulation; atoms = ica) # atoms is an vector of indices
(4, 1.1681526249035976)
```
Expand All @@ -58,8 +72,12 @@ function most_representative_structure(simulation::Simulation; atoms = nothing)
indices = PDBTools.index.(atoms)
elseif atoms isa AbstractVector{Int}
indices = atoms
elseif atoms isa String
indices = PDBTools.index.(
PDBTools.select(MolSimToolkit.atoms(simulation), atoms)
)
else
throw(ArgumentError("atoms must be an AbstractVector{<:PDBTools.Atom} or an AbstractVector{<:Int}, with atom indices."))
throw(ArgumentError("atoms must be a selection string, an array of PDBTools.Atom's or vector of integers with atom indices."))
end
end
if length(indices) == 0
Expand Down Expand Up @@ -97,12 +115,18 @@ end
using MolSimToolkit, MolSimToolkit.Testing, PDBTools
simulation = Simulation(Testing.namd_pdb, Testing.namd_traj)
calphas = select(atoms(simulation), "name CA")
imin, rmsdmin = most_representative_structure(simulation)
@test imin == 4
@test rmsdmin 1.1681514813293536
imin, rmsdmin = most_representative_structure(simulation; atoms = calphas)
@test imin == 4
@test rmsdmin 1.1681514813293536
imin, rmsdmin = most_representative_structure(simulation; atoms = PDBTools.index.(calphas))
@test imin == 4
@test rmsdmin 1.1681514813293536
imin, rmsdmin = most_representative_structure(simulation; atoms = "protein and name CA")
@test imin == 4
@test rmsdmin 1.1681514813293536
@test_throws ArgumentError most_representative_structure(simulation; atoms = 1)
@test_throws ArgumentError most_representative_structure(simulation; atoms = Int[])
end

0 comments on commit 4095020

Please sign in to comment.