-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from MurrellGroup/simplify-properties
Simplify properties
- Loading branch information
Showing
17 changed files
with
374 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
name = "ProteinChains" | ||
uuid = "b8e8f2a5-48d3-44f1-ba0d-c71cb7726ff8" | ||
authors = ["Anton Oresten <[email protected]> and contributors"] | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
|
||
[deps] | ||
AssigningSecondaryStructure = "8ed43e74-60fb-4e11-99b9-91deed37aef7" | ||
Backboner = "9ac9c2a2-1cfe-46d3-b3fd-6fa470ea56a7" | ||
BioStructures = "de9282ab-8554-53be-b2d6-f6c222edabfc" | ||
DynamicStructs = "e139c391-eeee-4818-b359-c8725224fb1f" | ||
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
PeriodicTable = "7b2266bf-644c-5ea3-82d8-af4bbd25a884" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
|
||
[compat] | ||
AssigningSecondaryStructure = "0.5" | ||
Backboner = "0.12" | ||
BioStructures = "4" | ||
DynamicStructs = "0.1" | ||
HDF5 = "0.17" | ||
LinearAlgebra = "1" | ||
PeriodicTable = "1" | ||
julia = "1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
using PeriodicTable: elements | ||
|
||
const ELEMENT_SYMBOL_TO_ATOMIC_NUMBER = Dict(uppercase(elements[atomic_number].symbol) => atomic_number for atomic_number in 1:118) | ||
const ATOMIC_NUMBER_TO_ELEMENT_SYMBOL = Dict(n => s for (s, n) in ELEMENT_SYMBOL_TO_ATOMIC_NUMBER) | ||
const ELEMENT_SYMBOL_TO_NUMBER = Dict(uppercase(elements[number].symbol) => number for number in 1:118) | ||
const number_TO_ELEMENT_SYMBOL = Dict(n => s for (s, n) in ELEMENT_SYMBOL_TO_NUMBER) | ||
|
||
element_symbol_to_atomic_number(element_symbol::AbstractString) = ELEMENT_SYMBOL_TO_ATOMIC_NUMBER[uppercase(strip(element_symbol))] | ||
atomic_number_to_element_symbol(atomic_number::Integer) = ATOMIC_NUMBER_TO_ELEMENT_SYMBOL[atomic_number] | ||
element_symbol_to_number(element_symbol::AbstractString) = ELEMENT_SYMBOL_TO_NUMBER[uppercase(strip(element_symbol))] | ||
number_to_element_symbol(number::Integer) = number_TO_ELEMENT_SYMBOL[number] | ||
|
||
pad_atom_name(name::AbstractString, element_symbol::AbstractString) = rpad(" "^(2-length(strip(element_symbol)))*strip(name), 4) | ||
|
||
encode_atom_name(name::AbstractString, element_symbol::AbstractString) = reinterpret(UInt32, codeunits(pad_atom_name(name, element_symbol)))[1] | ||
decode_atom_name(name::UInt32) = String(reinterpret(UInt8, [name])) | ||
|
||
mutable struct Atom{T<:AbstractFloat} | ||
struct Atom{T<:AbstractFloat} | ||
name::UInt32 | ||
atomic_number::Int8 | ||
number::Int8 | ||
x::T | ||
y::T | ||
z::T | ||
end | ||
|
||
Atom(name::UInt32, atomic_number::Integer, x::T, y::T, z::T) where T = Atom{T}(name, atomic_number, x, y, z) | ||
Atom(name::AbstractString, element_symbol::AbstractString, coords::AbstractVector{<:AbstractFloat}) = | ||
Atom(encode_atom_name(name, element_symbol), element_symbol_to_atomic_number(element_symbol), coords...) | ||
Atom{T}(atom::Atom) where T = Atom{T}(atom.name, atom.number, atom.x, atom.y, atom.z) | ||
|
||
coords(atom::Atom) = [atom.x, atom.y, atom.z] | ||
@inline Atom(name::UInt32, number::Integer, x::T, y::T, z::T) where T = Atom{T}(name, number, x, y, z) | ||
@inline Atom(name::AbstractString, element_symbol::AbstractString, x::T, y::T, z::T) where T = | ||
Atom(encode_atom_name(name, element_symbol), element_symbol_to_number(element_symbol), x, y, z) | ||
|
||
Base.summary(atom::Atom) = "$(elements[atom.atomic_number].name) atom at [$(atom.x), $(atom.y), $(atom.z)])" | ||
@inline Atom(name, number, coords::AbstractVector{T}) where T = Atom(name, number, coords...) | ||
|
||
function offset!(atom::Atom, coords::Vector{<:Real}) | ||
@assert length(coords) == 3 | ||
atom.x += coords[1] | ||
atom.y += coords[2] | ||
atom.z += coords[3] | ||
return atom | ||
end | ||
coords(atom::Atom) = SVector(atom.x, atom.y, atom.z) | ||
|
||
Base.summary(atom::Atom) = "$(elements[atom.number].name) atom at [$(atom.x), $(atom.y), $(atom.z)])" | ||
|
||
Base.show(io::IO, atom::Atom{T}) where T = print(io, | ||
"Atom(\"$(decode_atom_name(atom.name))\", \"$(number_to_element_symbol(atom.number))\", $(coords(atom)))") |
Oops, something went wrong.