Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Dec 30, 2023
1 parent 040a6a5 commit 40f4de7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/backbone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ end
@inline Base.getindex(backbone::Backbone, r::AbstractVector{<:Integer}) = Backbone(backbone.coords[:, r])
@inline Base.view(backbone::Backbone, I...) = Backbone(view(backbone.coords, :, I...))

@inline Base.setindex!(backbone::Backbone, coords::AbstractVector, i::Integer) = (backbone[i] .= coords)
@inline Base.setindex!(backbone::Backbone, coords::AbstractMatrix, r::AbstractVector{<:Integer}) = (backbone[r].coords .= coords)
@inline Base.setindex!(backbone::Backbone, coords::AbstractVector, i::Integer) = (backbone.coords[:, i] .= coords)
@inline Base.setindex!(backbone::Backbone, coords::AbstractMatrix, r::AbstractVector{<:Integer}) = (backbone.coords[:, r] .= coords)
30 changes: 1 addition & 29 deletions src/protein/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,4 @@ function writepdb(protein::Vector{Chain}, filename, header=:auto, footer=:auto)
PDBTools.writePDB(atoms, filename, header=header, footer=footer)
end

pdb_to_protein, protein_to_pdb = readpdb, writepdb


function oxygen_coord_matrix(chain_id::AbstractString, oxygens::Vector{PDBTools.Atom})
chain_oxygens = filter(a -> PDBTools.chain(a) == chain_id, oxygens)
coords = Matrix{Float32}(undef, 3, length(chain_oxygens))
for (i, atom) in enumerate(chain_oxygens)
coords[:, i] = [atom.x, atom.y, atom.z]
end
return coords
end

# Alternative to oxygen_coords function in src/protein/oxygen.jl to get exact coordinates of oxygen atoms
function pdb_oxygen_coords(filename::String)
atoms = PDBTools.readPDB(filename)
chain_ids = unique(PDBTools.chain.(atoms))
oxygens = PDBTools.Atom[]
i = 1
while i <= length(atoms) - 3
if atoms[i].name == "N" && atoms[i+1].name == "CA" && atoms[i+2].name == "C" && atoms[i+3].name == "O"
push!(oxygens, atoms[i+3])
i += 4
else
i += 1
end
end
oxygen_coord_matrices = [oxygen_coord_matrix(chain_id, oxygens) for chain_id in chain_ids]
return oxygen_coord_matrices
end
pdb_to_protein, protein_to_pdb = readpdb, writepdb
9 changes: 9 additions & 0 deletions test/backbone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@
@test length(backbone) == 20
@test size(backbone) == (20,)
@test backbone[1] == coords[:, 1]
@test backbone[1:2] == Backbone(coords[:, 1:2])

backbone[1] = [0.0, 0.0, 0.0]
backbone[1:2] = [0.0 0.0; 0.0 0.0; 0.0 0.0]
@test backbone[1] == [0.0, 0.0, 0.0]
@test backbone[1:2] == Backbone([0.0 0.0; 0.0 0.0; 0.0 0.0])

@test length(Backbone{Float32}(undef, 20)) == 20
@test length(Backbone(randn(3, 3, 5))) == 15

end

0 comments on commit 40f4de7

Please sign in to comment.