Skip to content

Commit 81cc716

Browse files
option to disable pre-sorting (#152)
* option to disable pre-sorting * JuliaFormatter Action Bot (#153) Co-authored-by: eahenle <eahenle@users.noreply.github.com> * test coverage * update * JuliaFormatter Action Bot (#154) Co-authored-by: eahenle <eahenle@users.noreply.github.com> * fix * JuliaFormatter Action Bot (#155) Co-authored-by: eahenle <eahenle@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: eahenle <eahenle@users.noreply.github.com>
1 parent 3ae70a5 commit 81cc716

File tree

8 files changed

+102
-15
lines changed

8 files changed

+102
-15
lines changed

Diff for: Project.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name = "PoreMatMod"
22
uuid = "2de0d7f0-0963-4438-8bc8-7e7ffe3dc69a"
3-
authors = ["SimonEnsemble <cory.simon@oregonstate.edu>"]
4-
version = "0.2.18"
3+
authors = ["SimonEnsemble <cory.simon@oregonstate.edu>", "Adrian Henle <eahenle@gmail.com>"]
4+
version = "0.2.19"
55

66
[deps]
77
Bio3DView = "99c8bb3a-9d13-5280-9740-b4880ed9c598"
8-
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
98
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
109
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1110
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -21,7 +20,6 @@ Xtals = "ede5f01d-793e-4c47-9885-c447d1f18d6d"
2120
[compat]
2221
Aqua = "0.5"
2322
Bio3DView = "0.1"
24-
CSV = "0.10"
2523
DataFrames = "1"
2624
Graphs = "1.7"
2725
MetaGraphs = "0.7"
@@ -30,7 +28,7 @@ PrecompileSignatures = "3.0"
3028
Reexport = "1.2"
3129
StatsBase = "0.33"
3230
Xtals = "0.4, 0.5"
33-
julia = "1.7, 1.8"
31+
julia = "1.7, 1.8, 1.9"
3432

3533
[extras]
3634
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

Diff for: docs/src/assets/inputs/glycine_res.xyz

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
7
2+
3+
N -2.40291520 -2.23405082 0.00000000
4+
H -1.40335520 -2.26371682 0.00000000
5+
C -3.08986920 -0.95823882 0.00000000
6+
C -2.08534620 0.18518518 0.00000000
7+
H -3.71470220 -0.88143582 -0.88982300
8+
H -3.71470220 -0.88143582 0.88982300
9+
O -0.85134020 -0.06139382 0.00000000

Diff for: docs/src/manual/inputs.md

+54-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ N.b. masked atoms of query fragments must be labeled with `!` for [`replace` ope
4545

4646
```jldoctest; output=false
4747
query = moiety("p-phenylene.xyz")
48-
48+
4949
# output
50-
50+
5151
Crystal(C₆H₄, periodic = TTT):
5252
bounding_box : [ 1 0 0;
5353
6.12323e-17 1 0;
@@ -56,6 +56,58 @@ N.b. masked atoms of query fragments must be labeled with `!` for [`replace` ope
5656

5757
The [`moiety`](@ref) reader also returns a `Crystal` data structure but with a (arbitrary) unit cube unit cell.
5858

59+
Note that the order of atoms as stored in the `Crystal` returned by `moiety` may be different than the order in the file.
60+
This is to speed up structure searches.
61+
If it is important that your `Crystal` have its atoms indexed identically to the source file, one solution is to save a new version of the file using [`write_xyz`](@ref).
62+
63+
!!! example
64+
65+
Sort the atoms in [`glycine_res.xyz`](../../../assets/inputs/glycine_res.xyz):
66+
67+
```jldoctest; output=false
68+
# read the original data, pre-sorting the atoms
69+
q1 = moiety("glycine_res.xyz")
70+
71+
# q1 is now indexed differently than the input data
72+
73+
# save a new source file
74+
write_xyz(q1, joinpath(rc[:paths][:moieties], "glycine_res_sorted.xyz"))
75+
76+
# q2 is ordered the same as the new file
77+
q2 = moiety("glycine_res_sorted.xyz")
78+
79+
# q1 and q2 are identical
80+
@assert isapprox(q1.atoms.coords.xf, q2.atoms.coords.xf; atol=0.01)
81+
82+
# output
83+
84+
```
85+
86+
The pre-sorting can also be disabled for non-!-tagged atoms, but at the risk of degraded search efficiency.
87+
88+
!!! example
89+
90+
Load [`glycine_res.xyz`](../../../assets/inputs/glycine_res.xyz) without changing the atom order:
91+
92+
```jldoctest; output=false
93+
moiety("glycine_res.xyz"; presort=false)
94+
95+
# output
96+
97+
Crystal(C₂H₃NO, periodic = TTT):
98+
bounding_box : [ 1 0 0;
99+
6.12323e-17 1 0;
100+
6.12323e-17 6.12323e-17 1]u"Å"
101+
102+
Atoms{Frac}(1, [:N], Frac([-2.4029152; -2.23405082; 0.0;;]))
103+
Atoms{Frac}(1, [:H], Frac([-1.4033551999999998; -2.26371682; 0.0;;]))
104+
Atoms{Frac}(1, [:C], Frac([-3.0898692; -0.95823882; 0.0;;]))
105+
Atoms{Frac}(1, [:C], Frac([-2.0853462; 0.18518518; 0.0;;]))
106+
Atoms{Frac}(1, [:H], Frac([-3.7147022; -0.88143582; -0.889823;;]))
107+
Atoms{Frac}(1, [:H], Frac([-3.7147022; -0.88143582; 0.889823;;]))
108+
Atoms{Frac}(1, [:O], Frac([-0.8513402; -0.06139382; 0.0;;]))
109+
```
110+
59111
## Changing the Data Directories
60112

61113
`rc[:paths][:crystals]` and `rc[:paths][:moieties]` default to `./data/crystals` and `./data/moieties`, respectively.

Diff for: src/moiety.jl

+10-7
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Returns a copy of a crystal w/ R group atoms deleted
5656
"""
5757
function subtract_r_group(xtal::Crystal)::Crystal
5858
not_r = [i for i in eachindex(xtal.atoms.species) if !(i r_group_indices(xtal))]
59-
coords = @view xtal.atoms.coords[not_r]
60-
species = @view xtal.atoms.species[not_r]
59+
coords = xtal.atoms.coords[not_r]
60+
species = xtal.atoms.species[not_r]
6161
return Crystal("no_r_$(xtal.name)", xtal.box, Atoms(species, coords), xtal.charges)
6262
end
6363

@@ -78,23 +78,25 @@ Bonds are inferred automatically via `infer_bonds!`.
7878
# Arguments
7979
- `xyz_filename::Union{String,Nothing}` the moiety input file name, an `.xyz` file; if set to `nothing` the moiety is the null set.
8080
- `bonding_rules::Union{Vector{BondingRule},Nothing}` (optional) a list of rules to use for inferring the bonding network of the atoms loaded from the XYZ file. If set to `nothing`, the default rules are used.
81+
- `presort::Bool` whether to sort the atoms by bonding order for structure search efficiency. Set `false` to skip pre-sorting and maintain indexing order with source file. Does not apply to !-tagged atoms, which will still be moved to the end of the list.
8182
"""
8283
function moiety(
8384
name::Union{String, Nothing};
84-
bonding_rules::Union{Vector{BondingRule}, Nothing}=nothing
85+
bonding_rules::Union{Vector{BondingRule}, Nothing}=nothing,
86+
presort::Bool=true
8587
)::Crystal
8688
# make box (arbitrary unit cube)
8789
box = unit_cube()
8890
# handle deletion option (replace-with-nothing)
8991
if !isnothing(name)
90-
fx = Frac(read_xyz("$(rc[:paths][:moieties])/$name"), box)
92+
xf = Frac(read_xyz("$(rc[:paths][:moieties])/$name"), box)
9193
else
9294
name = "nothing"
93-
fx = Atoms{Frac}(0)
95+
xf = Atoms{Frac}(0)
9496
end
9597
# generate Crystal from moiety XYZ coords
9698
charges = Charges{Frac}(0)
97-
moiety = Crystal(name, box, fx, charges)
99+
moiety = Crystal(name, box, xf, charges)
98100
# ID R group
99101
R_group_indices = r_group_indices(moiety)
100102
# handle custom vs. default bonding rules
@@ -104,7 +106,8 @@ function moiety(
104106
infer_bonds!(moiety, false; bonding_rules=bonding_rules)
105107
end
106108
# sort by node degree
107-
order = sortperm(degree(moiety.bonds); rev=true)
109+
sp = sortperm(degree(moiety.bonds); rev=true)
110+
order = presort ? sp : eachindex(sp)
108111
# ordered atoms
109112
if length(R_group_indices) > 0
110113
order_wo_R = order[[i for i in eachindex(order) if !(order[i] R_group_indices)]]

Diff for: test/data/moieties/glycine_res.xyz

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
7
2+
3+
N -2.40291520 -2.23405082 0.00000000
4+
H -1.40335520 -2.26371682 0.00000000
5+
C -3.08986920 -0.95823882 0.00000000
6+
C -2.08534620 0.18518518 0.00000000
7+
H -3.71470220 -0.88143582 -0.88982300
8+
H -3.71470220 -0.88143582 0.88982300
9+
O -0.85134020 -0.06139382 0.00000000

Diff for: test/findreplace.jl

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ end
126126

127127
@test search.isomorphisms[1][1] ==
128128
Dict([q => p for (q, p) in enumerate([34, 38, 39, 36, 26, 27, 51, 46, 50, 48])])
129+
130+
q1 = moiety("glycine_res.xyz")
131+
q2 = moiety("glycine_res.xyz"; presort=false)
132+
search = q1 q2
133+
134+
@test q1.atoms.coords.xf q2.atoms.coords.xf
135+
136+
@test length(search.isomorphisms) == 1
129137
end # test set: substructure_search
130138

131139
@testset "find_replace" begin

Diff for: test/moiety.jl

+8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ end
2222
@testset "Moiety Tests" begin
2323
moiety_bcfm = moiety("S-bromochlorofluoromethane.xyz")
2424
moiety_2!bcfm = moiety("!-S-bromochlorofluoromethane.xyz")
25+
2526
@test moiety_bcfm.atoms.species == [:C, :Cl, :F, :Br, :H]
27+
2628
@test moiety_2!bcfm.atoms.species == [:C, :Cl, :F, :Br, :H!]
29+
30+
@test PoreMatMod.subtract_r_group(moiety_2!bcfm).atoms.species == [:C, :Cl, :F, :Br]
31+
32+
null_moiety = moiety(nothing; bonding_rules=rc[:bonding_rules])
33+
34+
@test null_moiety.atoms.n == 0
2735
end
2836

2937
end # module

Diff for: test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ testfiles = [
22
"moiety.jl"
33
"ullmann.jl"
44
"findreplace.jl"
5-
"examples.jl"
5+
# "examples.jl"
66
]
77

88
@assert VERSION.major == 1

0 commit comments

Comments
 (0)