Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/src/public/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ SecondaryStructureTable
secondary_structure_by_idx
secondary_structures
nsecondary_structures
parent_secondary_structure
sort_secondary_structures!
Base.delete!(::SecondaryStructure)
Base.push!(::Chain{T}, ::SecondaryStructure{T}) where T
```

## Fragments
Expand Down Expand Up @@ -145,7 +143,6 @@ nfragments
parent_fragment
sort_fragments!
Base.delete!(::Fragment)
Base.push!(::SecondaryStructure{T}, ::Fragment{T}) where T
Base.push!(::Chain{T}, ::Fragment{T}) where T
```

Expand Down
18 changes: 10 additions & 8 deletions docs/src/tutorials/core_components.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,45 +532,47 @@ Now, that we learned about chains, we can take a look at the secondary structure
s = System()
chain = Chain(Molecule(s))
ss1 = SecondaryStructure(
chain,
Residue(chain, 1),
Residue(chain, 2),
1,
SecondaryStructureElement.Helix;
name="H1"
)

ss2 = SecondaryStructure(
chain,
Residue(chain, 3),
Residue(chain, 4),
2,
SecondaryStructureElement.Coil;
name="C1"
)

ss3 = SecondaryStructure(
chain,
Residue(chain, 5),
Residue(chain, 6),
3,
SecondaryStructureElement.Strand;
name="S1"
)
ss4 = SecondaryStructure(
chain,
Residue(chain, 7),
Residue(chain, 8),
4,
SecondaryStructureElement.Turn;
name="T1"
)

ss3.type = SecondaryStructureElement.Helix
println("Number of secondary structures: ", nsecondary_structures(s))

# get all helices of the chain
helices = (filter(sst -> sst.type == ss1.type, secondary_structures(chain)))
filter(sst -> sst.type == SecondaryStructureElement.Helix, secondary_structures(chain))
```

Number of secondary structures: 4

| **\#** | **idx** | **number** | **type** | **name** |
|-------:|:--------|:-----------|:---------|:---------|
| 1 | 3 | 1 | Helix | H1 |
| 2 | 5 | 3 | Helix | S1 |
| 1 | 5 | 1 | Helix | H1 |

In addition, we can compute the secondary structures for an input file:

Expand Down
4 changes: 2 additions & 2 deletions src/BiochemicalAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ include("core/system_internals/_atom_table.jl")
include("core/system_internals/_bond_table.jl")
include("core/system_internals/_molecule_table.jl")
include("core/system_internals/_chain_table.jl")
include("core/system_internals/_secondary_structure_table.jl")
include("core/system_internals/_fragment_table.jl")
include("core/system_internals/_secondary_structure_table.jl")
include("core/system.jl")

# system components
Expand All @@ -63,8 +63,8 @@ include("core/atom.jl")
include("core/bond.jl")
include("core/molecule.jl")
include("core/chain.jl")
include("core/secondary_structure.jl")
include("core/fragment.jl")
include("core/secondary_structure.jl")

# molgraph
include("core/moleculargraph_wrapper.jl")
Expand Down
8 changes: 0 additions & 8 deletions src/core/atom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ end
chain_by_idx(atom._sys, atom.chain_idx)
end

@inline function parent_secondary_structure(atom::Atom)
pf = parent_fragment(atom)

isnothing(pf) || isnothing(pf.secondary_structure_idx) ?
nothing :
secondary_structure_by_idx(parent(atom), pf.secondary_structure_idx)
end

@inline function parent_fragment(atom::Atom)
isnothing(atom.fragment_idx) ?
nothing :
Expand Down
89 changes: 8 additions & 81 deletions src/core/fragment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Mutable representation of an individual fragment in a system.
- `flags::Flags`
- `molecule_idx::Int`
- `chain_idx::Int`
- `secondary_structure_idx::Int`

# Constructors
```julia
Expand Down Expand Up @@ -96,14 +95,6 @@ const Fragment{T} = AtomContainer{T, :Fragment}
fragment_by_idx(sys, idx)
end

@inline function Fragment(
ss::SecondaryStructure{T},
number::Int;
kwargs...
) where T
Fragment(parent_chain(ss), number; secondary_structure_idx = ss.idx, kwargs...)
end

"""
FragmentTable{T} <: AbstractSystemComponentTable{T}

Expand Down Expand Up @@ -140,7 +131,6 @@ end

@inline parent_molecule(frag::Fragment) = molecule_by_idx(parent(frag), frag.molecule_idx)
@inline parent_chain(frag::Fragment) = chain_by_idx(parent(frag), frag.chain_idx)
@inline parent_secondary_structure(frag::Fragment) = secondary_structure_by_idx(parent(frag), frag.secondary_structure_idx)

@doc raw"""
parent_fragment(::Atom)
Expand Down Expand Up @@ -178,26 +168,22 @@ Returns a `FragmentTable{T}` containing all fragments of the given atom containe
- `variant::Union{Nothing, FragmentVariantType} = nothing`
- `molecule_idx::MaybeInt = nothing`
- `chain_idx::MaybeInt = nothing`
- `secondary_structure_idx::MaybeInt = nothing`
All keyword arguments limit the results to fragments matching the given IDs or variant type.
Keyword arguments set to `nothing` are ignored.
"""
function fragments(sys::System{T} = default_system();
variant::Union{Nothing, FragmentVariantType} = nothing,
molecule_idx::MaybeInt = nothing,
chain_idx::MaybeInt = nothing,
secondary_structure_idx::MaybeInt = nothing
chain_idx::MaybeInt = nothing
) where T
isnothing(variant) &&
isnothing(molecule_idx) &&
isnothing(chain_idx) &&
isnothing(secondary_structure_idx) &&
return FragmentTable{T}(sys, copy(sys._fragments.idx))
_filter_fragments(frag ->
(isnothing(variant) || frag.variant == something(variant)) &&
(isnothing(molecule_idx) || frag.molecule_idx == something(molecule_idx)) &&
(isnothing(chain_idx) || frag.chain_idx == something(chain_idx)) &&
(isnothing(secondary_structure_idx) || frag.secondary_structure_idx == something(secondary_structure_idx)),
(isnothing(chain_idx) || frag.chain_idx == something(chain_idx)),
sys
)
end
Expand Down Expand Up @@ -283,23 +269,6 @@ end

@inline nfragments(ct::ChainTable; kwargs...) = length(fragments(ct; kwargs...))

#=
SecondaryStructure fragments
=#
@inline fragments(ss::SecondaryStructure; kwargs...) = fragments(parent(ss); secondary_structure_idx = ss.idx, kwargs...)
@inline nfragments(ss::SecondaryStructure; kwargs...) = nfragments(parent(ss); secondary_structure_idx = ss.idx, kwargs...)

@inline function fragments(st::SecondaryStructureTable;
variant::Union{Nothing, FragmentVariantType} = nothing
)
idx = Set(st.idx)
isnothing(variant) ?
_filter_fragments(frag -> frag.secondary_structure_idx in idx, st._sys) :
_filter_fragments(frag -> frag.secondary_structure_idx in idx && frag.variant == something(variant), st._sys)
end

@inline nfragments(st::SecondaryStructureTable; kwargs...) = length(fragments(st; kwargs...))

"""
delete!(::Fragment)
delete!(::FragmentTable)
Expand Down Expand Up @@ -347,23 +316,6 @@ new `idx`.
chain
end

"""
push!(::SecondaryStructure{T}, ::Fragment{T})

Creates a copy of the given fragment in the given SecondaryStructure. The new fragment is automatically assigned a
new `idx`.
"""
@inline function Base.push!(ss::SecondaryStructure{T}, frag::Fragment{T}) where T
Fragment(ss, frag.number;
name = frag.name,
variant = frag.variant,
properties = frag.properties,
flags = frag.flags
)
ss
end


#=
Fragment atoms
=#
Expand Down Expand Up @@ -420,19 +372,6 @@ See [`Fragment`](@ref)
Fragment(chain, number; variant = FragmentVariant.Nucleotide, kwargs...)
end


"""
Nucleotide(ss::SecondaryStructure, number::Int)

`Fragment` constructor defaulting to the [`FragmentVariant.Nucleotide`](@ref FragmentVariant) variant.

# Supported keyword arguments
See [`Fragment`](@ref)
"""
@inline function Nucleotide(ss::SecondaryStructure, number::Int; kwargs...)
Fragment(ss, number; variant = FragmentVariant.Nucleotide, kwargs...)
end

"""
$(TYPEDSIGNATURES)

Expand Down Expand Up @@ -478,7 +417,7 @@ fragments of the given atom container or table.
See [`fragments`](@ref)
"""
@inline function nucleotides(
ac::Union{Chain, ChainTable, SecondaryStructure, SecondaryStructureTable, Molecule, MoleculeTable, System} = default_system();
ac::Union{Chain, ChainTable, Molecule, MoleculeTable, System} = default_system();
kwargs...
)
fragments(ac; variant = FragmentVariant.Nucleotide, kwargs...)
Expand All @@ -497,7 +436,7 @@ atom container.
See [`fragments`](@ref)
"""
@inline function nnucleotides(
ac::Union{Chain, ChainTable, SecondaryStructure, SecondaryStructureTable, Molecule, MoleculeTable, System} = default_system();
ac::Union{Chain, ChainTable, Molecule, MoleculeTable, System} = default_system();
kwargs...
)
nfragments(ac; variant = FragmentVariant.Nucleotide, kwargs...)
Expand All @@ -516,7 +455,7 @@ table.
length(filter(isnucleotide, ft))
end

@inline function nnucleotides(ct::Union{ChainTable, SecondaryStructureTable, MoleculeTable})
@inline function nnucleotides(ct::Union{ChainTable, MoleculeTable})
nfragments(ct; variant = FragmentVariant.Nucleotide)
end

Expand Down Expand Up @@ -546,18 +485,6 @@ See [`Fragment`](@ref)
Fragment(chain, number; variant = FragmentVariant.Residue, kwargs...)
end

"""
Residue(ss::SecondaryStructure, number::Int)

`Fragment` constructor defaulting to the [`FragmentVariant.Residue`](@ref FragmentVariant) variant.

# Supported keyword arguments
See [`Fragment`](@ref)
"""
@inline function Residue(ss::SecondaryStructure, number::Int; kwargs...)
Fragment(ss, number; variant = FragmentVariant.Residue, kwargs...)
end

"""
$(TYPEDSIGNATURES)

Expand Down Expand Up @@ -603,7 +530,7 @@ fragments of the given atom container or table.
See [`fragments`](@ref)
"""
@inline function residues(
ac::Union{Chain, ChainTable, SecondaryStructure, SecondaryStructureTable, Molecule, MoleculeTable, System} = default_system();
ac::Union{Chain, ChainTable, Molecule, MoleculeTable, System} = default_system();
kwargs...
)
fragments(ac; variant = FragmentVariant.Residue, kwargs...)
Expand All @@ -622,7 +549,7 @@ atom container.
See [`fragments`](@ref)
"""
@inline function nresidues(
ac::Union{Chain, ChainTable, SecondaryStructure, SecondaryStructureTable, Molecule, MoleculeTable, System} = default_system();
ac::Union{Chain, ChainTable, Molecule, MoleculeTable, System} = default_system();
kwargs...
)
nfragments(ac; variant = FragmentVariant.Residue, kwargs...)
Expand All @@ -641,7 +568,7 @@ table.
length(filter(isresidue, ft))
end

@inline function nresidues(ct::Union{ChainTable, SecondaryStructureTable, MoleculeTable})
@inline function nresidues(ct::Union{ChainTable, MoleculeTable})
nfragments(ct; variant = FragmentVariant.Residue)
end

Expand Down
Loading
Loading