Skip to content

Commit

Permalink
Merge branch 'pdbexport'
Browse files Browse the repository at this point in the history
  • Loading branch information
gp0 committed Mar 29, 2015
2 parents 41b8fae + dbbc512 commit c4ee374
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/PDB/pdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# sudo apt-get install numpy | unless you want to compile it..
# julia: Pkg.add("PyCall")
module PDB
export get_structure, get_chains, structure_to_matrix
export get_structure, get_chains, structure_to_matrix, export_to_pdb

using PyCall
using Formatting
@pyimport Bio.PDB as pdb

# get a structure from a PDB File
Expand Down Expand Up @@ -55,4 +56,23 @@ function structure_to_matrix(structure::PyObject)
return matrix
end

end
# Export a matrix of C_alpha atom coordinates to a PDB file
function export_to_pdb(residueName::String,chainID::String,matrix::Array{Float64,2}, filename::String)
lines = String[]

atomExpr = FormatExpr("{: <6}{: >5} {: >4}{: <1}{: >3} {: <1}{: >4}{: <1} {: >8}{: >8}{: >8}{: >6}{: >6} {: <4}{: >2}{: <2}\n")

for i in 1:size(matrix)[1]
line = format(atomExpr, "ATOM", i, "CA", " ", residueName, chainID, "1", " ", matrix[i,:][1], matrix[i,:][2], matrix[i,:][3], 1.0, 0.0, "A1", "C", " ")

push!(lines, line)
end

f = open(filename, "w")
write(f,lines)
close(f)

return lines
end

end
17 changes: 16 additions & 1 deletion test/pdb.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PyCall

struc = get_structure("2HHB.pdb")

# Extremely rudimentary test, basically do we get anything back from our PyCall?
Expand All @@ -13,4 +14,18 @@ chains = get_chains(struc)
@test size(chains[1]) == (141,3)
@test size(chains[2]) == (146,3)
@test size(chains[3]) == (141,3)
@test size(chains[4]) == (146,3)
@test size(chains[4]) == (146,3)

# PDB export test
P = [31.132 16.439 58.160;
6.870 17.784 4.702
]

f = open("pdb_export_test.pdb")
pdb_expected = convert(Array{String,1},readlines(f))

pdb_handler(r::Test.Success) = rm("pdb_exported_test.pdb")

Test.with_handler(pdb_handler) do
@test pdb_expected == export_to_pdb("VAL", "A", P, "pdb_exported_test.pdb")
end
2 changes: 2 additions & 0 deletions test/pdb_export_test.pdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ATOM 1 CA VAL A 1 31.132 16.439 58.16 1.0 0.0 A1 C
ATOM 2 CA VAL A 1 6.87 17.784 4.702 1.0 0.0 A1 C

0 comments on commit c4ee374

Please sign in to comment.