Skip to content

Commit

Permalink
System: allow string-based fields to be passed as AbstractStrings
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Kemmer <[email protected]>
  • Loading branch information
tkemmer committed Dec 17, 2024
1 parent 94d446e commit 4005bf8
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/core/atom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Atom(
number::Int,
element::ElementType;
# keyword arguments
name::String = "",
atom_type::String = "",
name::AbstractString = "",
atom_type::AbstractString = "",
r::Vector3{T} = Vector3{T}(0, 0, 0),
v::Vector3{T} = Vector3{T}(0, 0, 0),
F::Vector3{T} = Vector3{T}(0, 0, 0),
Expand Down Expand Up @@ -191,7 +191,7 @@ end
"""
atom_by_name(
ac::AbstractAtomContainer{T} = default_system(),
name::String
name::AbstractString
) -> Union{Nothing, Atom{T}}
Returns the first `Atom{T}` associated with the given `name` in `ac`. Returns nothing if no such
Expand All @@ -203,14 +203,14 @@ Any value other than `nothing` limits the result to atoms matching this frame ID
"""
@inline function atom_by_name(
ac::AbstractAtomContainer{T},
name::String;
name::AbstractString;
frame_id::MaybeInt = 1
) where T
idx = filter(atom -> atom.name == name, atoms(ac; frame_id = frame_id)).idx
isempty(idx) ? nothing : atom_by_idx(parent(ac), first(idx))
end

@inline function atom_by_name(name::String; kwargs...)
@inline function atom_by_name(name::AbstractString; kwargs...)
atom_by_name(default_system(), name; kwargs...)
end

Expand Down
2 changes: 1 addition & 1 deletion src/core/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Mutable representation of an individual chain in a system.
Chain(
mol::Molecule{T};
# keyword arguments
name::String = "",
name::AbstractString = "",
properties::Properties = Properties(),
flags::Flags = Flags()
)
Expand Down
4 changes: 2 additions & 2 deletions src/core/fragment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Fragment(
chain::Chain{T},
number::Int;
# keyword arguments
name::String = "",
name::AbstractString = "",
variant::FragmentVariantType = FragmentVariant.None,
properties::Properties = Properties(),
flags::Flags = Flags()
Expand All @@ -64,7 +64,7 @@ Fragment(
secondary_structure::SecondaryStructure{T},
number::Int;
# keyword arguments
name::String = "",
name::AbstractString = "",
variant::FragmentVariantType = FragmentVariant.None,
properties::Properties = Properties(),
flags::Flags = Flags()
Expand Down
4 changes: 2 additions & 2 deletions src/core/molecule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Mutable representation of an individual molecule in a system.
Molecule(
sys::System{T};
# keyword arguments
name::String = "",
name::AbstractString = "",
variant::MoleculeVariantType = MoleculeVariant.None,
properties::Properties = Properties(),
flags::Flags = Flags()
Expand All @@ -42,7 +42,7 @@ Creates a new `Molecule{T}` in the given system.
```julia
Molecule(;
#keyword arguments
name::String = "",
name::AbstractString = "",
variant::MoleculeVariantType = MoleculeVariant.None,
properties::Properties = Properties(),
flags::Flags = Flags()
Expand Down
4 changes: 2 additions & 2 deletions src/core/secondary_structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SecondaryStructure(
number::Int,
type::SecondaryStructureType;
# keyword arguments
name::String = "",
name::AbstractString = "",
properties::Properties = Properties(),
flags::Flags = Flags()
)
Expand All @@ -43,7 +43,7 @@ const SecondaryStructure{T} = AtomContainer{T, :SecondaryStructure}
chain::Chain,
number::Int,
type::SecondaryStructureType;
name::String="",
name::AbstractString="",
kwargs...
)
sys = parent(chain)
Expand Down
10 changes: 5 additions & 5 deletions src/core/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ Mutable representation of a biomolecular system.
- `flags::Flags`
# Constructors
System(name::String = "", properties::Properties = Properties(), flags::Flags = Flags())
System(name::AbstractString = "", properties::Properties = Properties(), flags::Flags = Flags())
Creates a new and empty `System{Float32}`.
System{T}(name::String = "", properties::Properties = Properties(), flags::Flags = Flags())
System{T}(name::AbstractString = "", properties::Properties = Properties(), flags::Flags = Flags())
Creates a new and empty `System{T}`.
"""
Expand All @@ -120,7 +120,7 @@ Creates a new and empty `System{T}`.
_curr_idx::Int

function System{T}(
name::String = "",
name::AbstractString = "",
properties::Properties = Properties(),
flags::Flags = Flags()
) where T
Expand All @@ -140,7 +140,7 @@ Creates a new and empty `System{T}`.
end

System(
name::String = "",
name::AbstractString = "",
properties::Properties = Properties(),
flags::Flags = Flags()
) = System{Float32}(name, properties, flags)
Expand Down Expand Up @@ -336,7 +336,7 @@ end
end

@inline Base.show(io::IO, ::MIME"text/plain", sc::SystemComponent) = show(io, sc)
@inline function Base.show(io::IO, sc::SystemComponent; display_name::String=repr(typeof(sc)))
@inline function Base.show(io::IO, sc::SystemComponent; display_name::AbstractString=repr(typeof(sc)))
print(io, "$display_name: ")
show(io, NamedTuple(_row_by_idx(_table(sc), sc._idx)))
end
Expand Down
4 changes: 2 additions & 2 deletions src/core/system_internals/_atom_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function Base.push!(
idx::Int,
number::Int,
element::ElementType;
name::String = "",
atom_type::String = "",
name::AbstractString = "",
atom_type::AbstractString = "",
r::Vector3{T} = Vector3{T}(0, 0, 0),
v::Vector3{T} = Vector3{T}(0, 0, 0),
F::Vector3{T} = Vector3{T}(0, 0, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/core/system_internals/_chain_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Base.push!(
ct::_ChainTable,
idx::Int,
molecule_idx::Int;
name::String = "",
name::AbstractString = "",
properties::Properties = Properties(),
flags::Flags = Flags()
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/system_internals/_fragment_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Base.push!(
molecule_idx::Int,
chain_idx::Int;
secondary_structure_idx::MaybeInt = nothing,
name::String = "",
name::AbstractString = "",
variant::FragmentVariantType = FragmentVariant.None,
properties::Properties = Properties(),
flags::Flags = Flags()
Expand Down
2 changes: 1 addition & 1 deletion src/core/system_internals/_molecule_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
function Base.push!(
mt::_MoleculeTable,
idx::Int = 0;
name::String = "",
name::AbstractString = "",
variant::MoleculeVariantType = MoleculeVariant.None,
properties::Properties = Properties(),
flags::Flags = Flags()
Expand Down
2 changes: 1 addition & 1 deletion src/core/system_internals/_secondary_structure_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Base.push!(
type::SecondaryStructureType,
molecule_idx::Int,
chain_idx::Int;
name::String = "",
name::AbstractString = "",
properties::Properties = Properties(),
flags::Flags = Flags()
)
Expand Down

0 comments on commit 4005bf8

Please sign in to comment.