Skip to content

Commit 28f7be9

Browse files
committed
Make trimming depend on the new "trim" option
1 parent c3b0dde commit 28f7be9

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/clustering.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ function _collapse_clusters(crystal::Crystal{Nothing}, clusters::Clusters, onlyn
14061406
atts = clusters.attributions[s]
14071407
neigh0 = neighbors(crystal.pge.g, s)
14081408
# @show s, atts
1409-
@toggleassert length(neigh0) 2
1409+
@toggleassert !crystal.options.trim || length(neigh0) 2
14101410
typisnotC = crystal.types[s] !== :C
14111411
for x in neigh0
14121412
d = x.v
@@ -1511,7 +1511,7 @@ function _find_clusters(c::Crystal{T}, guess::Bool, separate_metals::Bool)::Tupl
15111511
end
15121512

15131513
function find_clusters(_c::Crystal{T}) where T
1514-
c = trim_monovalent(_c)
1514+
c = _c.options.trim ? trim_monovalent(_c) : _c
15151515
structure = c.options.structure
15161516
clusterings = c.options.clusterings
15171517
ret = Vector{Tuple{Crystal{Nothing},Union{Int,Clusters}}}(undef, length(clusterings))
@@ -1549,6 +1549,7 @@ transformed into a new vertex, for each targeted clustering.
15491549
"""
15501550
function collapse_clusters(crystal::Crystal)
15511551
crystalclusters::Vector{Tuple{Crystal{Nothing},Union{Int,Clusters}}} = find_clusters(crystal)
1552+
# @show only(crystalclusters)[2]
15521553
ret = Vector{Crystal{Nothing}}(undef, length(crystalclusters))
15531554
alreadyexported = false
15541555
for (i, (cryst, clust)) in enumerate(crystalclusters)

src/options.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ These boolean options have a default value that may be determined by [`Bonding`]
387387
Default is false, unless [`StructureType`](@ref) is `MOF` or `Zeolite`.
388388
- `unify_sbu_decomposition`: apply the same rule to decompose both periodic and finite SBUs.
389389
Default is false.
390+
- `trim`: remove vertices with zero or one neighbor and transform vertices with exactly two
391+
neighbors into an edge, iteratively until convergence. Default is true and must be left
392+
to true if the topology needs to be compared to databases of topologies, which all use
393+
this convention.
390394
- `force_warn`: force printing warning and information even during `..._dataset` function
391395
calls. Default is false.
392396
- `label_for_type`: use the atom label instead of its type. Default is false.
@@ -450,6 +454,7 @@ struct Options
450454
cluster_simple_pe::Bool
451455
split_O_vertex::Bool
452456
unify_sbu_decomposition::Bool
457+
trim::Bool
453458
separate_metals::Union{Nothing,Bool}
454459
premerge_metalbonds::Bool
455460
max_polyhedron_radius::Int
@@ -500,6 +505,7 @@ struct Options
500505
cluster_simple_pe=true,
501506
split_O_vertex=nothing,
502507
unify_sbu_decomposition=false,
508+
trim=true,
503509
separate_metals=nothing,
504510
premerge_metalbonds=true,
505511
max_polyhedron_radius=4,
@@ -585,6 +591,7 @@ struct Options
585591
cluster_simple_pe,
586592
_split_O_vertex,
587593
unify_sbu_decomposition,
594+
trim,
588595
separate_metals,
589596
premerge_metalbonds,
590597
max_polyhedron_radius,

src/types.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,10 @@ end
497497
trimmed_crystal(c::Crystal{Nothing})
498498
499499
Rebuild the crystal after trimming its graph according to [`trim_topology`](@ref CrystalNets.trim_topology).
500+
Does nothing if `c.options.trim` is unset.
500501
"""
501502
function trimmed_crystal(c::Crystal{Nothing})
503+
c.options.trim || return c
502504
g = deepcopy(c.pge.g)
503505
remove_metal_cluster_bonds!(g, c.types, c.options)
504506
vmap, graph = trim_topology(g)
@@ -768,7 +770,11 @@ end
768770

769771

770772
function _collect_net!(ret::Vector{<:CrystalNet{D}}, encountered, idx, c, clustering) where D
771-
vmap, graph = trim_topology(c.pge.g)
773+
vmap, graph = if c.options.trim
774+
trim_topology(c.pge.g)
775+
else
776+
collect(1:length(c.types)), c.pge.g
777+
end
772778
types = c.types[vmap]
773779
idx > 1 && c.options.track_mapping isa Vector{Int} && c.options.keep_single_track && throw(ArgumentError("Cannot keep a single mapping track for multiple sub-nets. Please use keep_single_track=true only on single components with a single clustering."))
774780
opts = rev_permute_mapping!(c.options, vmap, length(c.types))

0 commit comments

Comments
 (0)