Skip to content

Commit

Permalink
Substructures: allow strings 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 d4d124a commit 94d446e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/substructures/smarts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ struct SMARTSQuery
query::String
query_graph::MolecularGraph.SMARTSMolGraph

function SMARTSQuery(query::String)
function SMARTSQuery(query::AbstractString)
new(query, MolecularGraph.smartstomol(query))
end
end

function _to_substructure(name, mol, m; adjacent_bonds=false)
function _to_substructure(name::AbstractString, mol::AbstractAtomContainer, m; adjacent_bonds::Bool = false)
matched_atoms = keys(m)

filter_atoms(atom -> atom.number matched_atoms, mol;
Expand All @@ -19,7 +19,7 @@ function _to_substructure(name, mol, m; adjacent_bonds=false)
)
end

function Base.match(query::SMARTSQuery, mol::AbstractAtomContainer; adjacent_bonds=false)
function Base.match(query::SMARTSQuery, mol::AbstractAtomContainer; adjacent_bonds::Bool = false)
mg_mol = convert(MolecularGraph.SDFMolGraph, mol)
matches = MolecularGraph.substruct_matches(mg_mol, query.query_graph)

Expand Down
14 changes: 8 additions & 6 deletions src/substructures/substructure.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
export Substructure, filter_atoms
export
Substructure,
filter_atoms

@auto_hash_equals struct Substructure{T<:Real, A<:AbstractAtomContainer{T}} <: AbstractAtomContainer{T}
name::String

parent::A

_atoms::AtomTable{T}
_bonds::BondTable{T}

properties::Properties

function Substructure{T,A}(
name::String,
name::AbstractString,
parent::A,
atoms::AtomTable{T},
bonds::BondTable{T},
Expand All @@ -22,14 +24,14 @@ export Substructure, filter_atoms
end

@inline Substructure(
name::String,
name::AbstractString,
parent::A,
atoms::AtomTable{T},
bonds::BondTable{T},
properties::Properties = parent.properties
) where {T, A} = Substructure{T, typeof(parent)}(name, parent, atoms, bonds, properties)

function filter_atoms(fn, mol::AbstractAtomContainer{T}; name="", adjacent_bonds=false) where T
function filter_atoms(fn, mol::AbstractAtomContainer; name::AbstractString="", adjacent_bonds::Bool=false)
atom_view = filter(fn, atoms(mol))
idxset = Set(atom_view.idx)
bond_view = filter(row ->
Expand Down

0 comments on commit 94d446e

Please sign in to comment.