BioJulia / BioStructures.jl

A Julia package to read, write and manipulate macromolecular structures
Other
93 stars 22 forks source link

Strip whitespaces from atom/element names #44

Open babaid opened 11 months ago

babaid commented 11 months ago

When looking at an atom record I discovered that the whitespaces do not get stripped from the atom/element names when they are parsed.

An example: Dict{String, AbstractAtom}(" CA " => Atom CA with serial ,.....

As you can see, CA is sorrounded by spaces, which is kind of inconvenient. I suggest changing the function parseatomname in pdb.jl to the following:

function parseatomname(line::String, line_n::Integer=1)
    try
            return strip(line[13:16])
    catch
            throw(PDBParseError("could not read atom name", line_n, line))
    end
end

And the same for parseelement.

jgreener64 commented 11 months ago

atomname and similar functions strip the white space, and you can index into residues without the white space.

It does need to be kept though, since different spacings are used to indicate e.g. C-alpha vs calcium, and this should be preserved on writing out.