consumer);
39 | }
40 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/core/TargetAssembler.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.core;
2 |
3 | import org.rcsb.strucmotif.domain.StructureSearchContext;
4 |
5 | /**
6 | * Where the magic happens. Lookup all word occurrences which need to be fulfilled and combine them in the most
7 | * efficient way.
8 | * Assembles the set of target structures to evaluate by focusing on the paths through targets. Basically, this is
9 | * subgraph isomorphism: the query is a graph, and we want to find all target structures which contain this query as a
10 | * subgraph.
11 | */
12 | public interface TargetAssembler {
13 | /**
14 | * Search: i.e. find all paths through all target structures which reasonably resemble the structure of the query
15 | * motif.
16 | * @param context the container to work on
17 | */
18 | void assemble(StructureSearchContext context);
19 | }
20 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/Pair.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain;
2 |
3 | /**
4 | * Defines a relation between 2 objects.
5 | * @param first 1st element
6 | * @param second 2nd element
7 | * @param the first type
8 | * @param the second type
9 | */
10 | public record Pair(F first, S second) {
11 | @Override
12 | public String toString() {
13 | return first + " - " + second;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/align/AlignmentResult.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain.align;
2 |
3 | /**
4 | * The result of an alignment.
5 | * @param transformation the transformation determined by the alignment
6 | * @param rmsd the alignment score
7 | */
8 | public record AlignmentResult(float[] transformation, float rmsd) {}
9 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/align/AtomPairingScheme.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain.align;
2 |
3 | import org.rcsb.strucmotif.domain.structure.LabelAtomId;
4 |
5 | import java.util.function.Predicate;
6 |
7 | /**
8 | * Schemes on which atoms (by name) to use to align residues. Each entry is actually a {@link Predicate} which tests
9 | * atom names and returns true if fall into that particular scheme.
10 | */
11 | public enum AtomPairingScheme implements Predicate {
12 | /**
13 | * Use everything.
14 | */
15 | ALL(s -> true),
16 | /**
17 | * Use alpha carbons only.
18 | */
19 | ALPHA_CARBON(s -> s.equals(LabelAtomId.CA) ||
20 | s.equals(LabelAtomId.C4_PRIME)),
21 | /**
22 | * Use beta carbons only.
23 | */
24 | BETA_CARBON(s -> s.equals(LabelAtomId.CB) ||
25 | s.equals(LabelAtomId.C1_PRIME)),
26 | /**
27 | * Use backbone atoms only.
28 | */
29 | BACKBONE(s -> s.equals(LabelAtomId.N) || s.equals(LabelAtomId.CA) || s.equals(LabelAtomId.C) ||
30 | s.equals(LabelAtomId.O) || s.equals(LabelAtomId.P) || s.equals(LabelAtomId.OP1) ||
31 | s.equals(LabelAtomId.OP2) || s.equals(LabelAtomId.C2_PRIME) || s.equals(LabelAtomId.C3_PRIME) ||
32 | s.equals(LabelAtomId.O3_PRIME) || s.equals(LabelAtomId.C4_PRIME) || s.equals(LabelAtomId.O4_PRIME) ||
33 | s.equals(LabelAtomId.C5_PRIME) || s.equals(LabelAtomId.O5_PRIME)),
34 | /**
35 | * Use side-chain atoms only.
36 | */
37 | SIDE_CHAIN(BACKBONE.predicate.negate()),
38 | /**
39 | * Use pseudo-atoms defined by {@link org.rcsb.strucmotif.domain.motif.ResiduePairDescriptor}.
40 | */
41 | PSEUDO_ATOMS(s -> s.equals(LabelAtomId.CA) || s.equals(LabelAtomId.CB) ||
42 | s.equals(LabelAtomId.C4_PRIME) || s.equals(LabelAtomId.C1_PRIME));
43 |
44 | private final Predicate predicate;
45 |
46 | AtomPairingScheme(Predicate predicate) {
47 | this.predicate = predicate;
48 | }
49 |
50 | @Override
51 | public boolean test(LabelAtomId s) {
52 | return predicate.test(s);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/bucket/Bucket.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain.bucket;
2 |
3 | import java.util.Set;
4 |
5 | /**
6 | * Represents a single file of the inverted index (e.g., AL-4-5-4). This file keeps track of all structures that contain
7 | * occurrences of the corresponding descriptor.
8 | */
9 | public interface Bucket {
10 | /**
11 | * All structures that contain occurrences of this descriptor.
12 | * @return a collection of structure indices
13 | */
14 | Set getStructureIndices();
15 |
16 | /**
17 | * True if there is another structure after the current one.
18 | * @return a boolean
19 | */
20 | boolean hasNextStructure();
21 |
22 | /**
23 | * True if there is another occurrence after the current one.
24 | * @return a boolean
25 | */
26 | boolean hasNextOccurrence();
27 |
28 | /**
29 | * Advance to the next structure, only safe if {@link #hasNextStructure()} is true.
30 | */
31 | void moveStructure();
32 |
33 | /**
34 | * Advance to the next structure, only safe if {@link #hasNextOccurrence()} is true.
35 | */
36 | void moveOccurrence();
37 |
38 | /**
39 | * The number of structures that contain this descriptor.
40 | * @return an int
41 | */
42 | int getStructureCount();
43 |
44 | /**
45 | * The total number of residue pairs registered in this bucket.
46 | * @return an int
47 | */
48 | int getResiduePairCount();
49 |
50 | /**
51 | * The current structure index.
52 | * @return a structure index
53 | */
54 | int getStructureIndex();
55 |
56 | /**
57 | * Convenience method that gives access to the current identifier represented by 2 ints.
58 | * @return the current residue indices
59 | */
60 | long getResiduePairIdentifier();
61 |
62 | /**
63 | * Move iterators back to start positions.
64 | */
65 | void reset();
66 |
67 | /**
68 | * Get the current occurrence start position associated with the current position pointer.
69 | * @return an int
70 | */
71 | int getStartPosition();
72 |
73 | /**
74 | * Get the current occurrence end position associated with the current position pointer.
75 | * @return an int
76 | */
77 | int getEndPosition();
78 | }
79 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/motif/AngleType.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain.motif;
2 |
3 | import org.rcsb.strucmotif.math.Algebra;
4 |
5 | /**
6 | * Binned representation of the angle between residues.
7 | */
8 | public enum AngleType {
9 | /**
10 | * [0, 10) deg.
11 | */
12 | A0,
13 | /**
14 | * [10, 30) deg.
15 | */
16 | A20,
17 | /**
18 | * [30, 50) deg.
19 | */
20 | A40,
21 | /**
22 | * [50, 70) deg.
23 | */
24 | A60,
25 | /**
26 | * [70, 90) deg.
27 | */
28 | A80,
29 | /**
30 | * [90, 110) deg.
31 | */
32 | A100,
33 | /**
34 | * [110, 130) deg.
35 | */
36 | A120,
37 | /**
38 | * [130, 150) deg.
39 | */
40 | A140,
41 | /**
42 | * [150, 170) deg.
43 | */
44 | A160,
45 | /**
46 | * [170, 180]
47 | */
48 | A180;
49 |
50 | /**
51 | * Cached values of this enum. Don't manipulate this array or things will burn.
52 | */
53 | public static final AngleType[] values = values();
54 |
55 | /**
56 | * Width of an angle bin.
57 | */
58 | public static final int BIN_SIZE = 20;
59 |
60 | /**
61 | * Convert enum to angle value in degree (basically the lower bound of the interval).
62 | * @return lower bound of angles landing in this bin
63 | */
64 | public int getIntRepresentation() {
65 | return ordinal() * BIN_SIZE;
66 | }
67 |
68 | /**
69 | * Convert angle in degrees to enum value. Will cap results into interval of possible values.
70 | * @param angle raw value
71 | * @return the corresponding bin
72 | */
73 | public static AngleType ofAngle(float angle) {
74 | int i = Math.round(angle / BIN_SIZE);
75 | if (i < 0) {
76 | return AngleType.A0;
77 | } else if (i >= values.length) {
78 | return AngleType.A180;
79 | } else {
80 | return values[i];
81 | }
82 | }
83 |
84 | /**
85 | * Convert the ordinal to enum value. Somewhat trivial. Will cap results into interval of possible values.
86 | * @param ordinal the ordinal to get
87 | * @return the corresponding bin
88 | */
89 | public static AngleType ofIntRepresentation(int ordinal) {
90 | return values[Algebra.capToInterval(0, ordinal, values.length)];
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/motif/DistanceType.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain.motif;
2 |
3 | import org.rcsb.strucmotif.math.Algebra;
4 |
5 | /**
6 | * Binned representation of the distance between residues.
7 | */
8 | public enum DistanceType {
9 | /**
10 | * [0, 0.5) A.
11 | */
12 | D0,
13 | /**
14 | * [0.5, 1.5) A.
15 | */
16 | D1,
17 | /**
18 | * [1.5, 2.5) A.
19 | */
20 | D2,
21 | /**
22 | * [2.5, 3.5) A.
23 | */
24 | D3,
25 | /**
26 | * [3.5, 4.5) A.
27 | */
28 | D4,
29 | /**
30 | * [4.5, 5.5) A.
31 | */
32 | D5,
33 | /**
34 | * [5.5, 6.5) A.
35 | */
36 | D6,
37 | /**
38 | * [6.5, 7.5) A.
39 | */
40 | D7,
41 | /**
42 | * [7.5, 8.5) A.
43 | */
44 | D8,
45 | /**
46 | * [8.5, 9.5) A.
47 | */
48 | D9,
49 | /**
50 | * [9.5, 10.5) A.
51 | */
52 | D10,
53 | /**
54 | * [10.5, 11.5) A.
55 | */
56 | D11,
57 | /**
58 | * [11.5, 12.5) A.
59 | */
60 | D12,
61 | /**
62 | * [12.5, 13.5) A.
63 | */
64 | D13,
65 | /**
66 | * [13.5, 14.5) A.
67 | */
68 | D14,
69 | /**
70 | * [14.5, 15.5) A.
71 | */
72 | D15,
73 | /**
74 | * [15.5, 16.5) A.
75 | */
76 | D16,
77 | /**
78 | * [16.5, 17.5) A.
79 | */
80 | D17,
81 | /**
82 | * [17.5, 18.5) A.
83 | */
84 | D18,
85 | /**
86 | * [18.5, 19.5) A.
87 | */
88 | D19,
89 | /**
90 | * [19.5, 20.5) A.
91 | */
92 | D20,
93 | /**
94 | * [20.5, 21.5) A.
95 | */
96 | D21,
97 | /**
98 | * [21.5, 22.5) A.
99 | */
100 | D22,
101 | /**
102 | * [22.5, 23.5) A.
103 | */
104 | D23,
105 | /**
106 | * [23.5, 24.5) A.
107 | */
108 | D24,
109 | /**
110 | * [24.5, 25.5) A.
111 | */
112 | D25,
113 | /**
114 | * [25.5, 26.5) A.
115 | */
116 | D26,
117 | /**
118 | * [26.5, 27.5) A.
119 | */
120 | D27,
121 | /**
122 | * [27.5, 28.5) A.
123 | */
124 | D28,
125 | /**
126 | * [28.5, 29.5) A.
127 | */
128 | D29,
129 | /**
130 | * [29.5, 30.5) A.
131 | */
132 | D30,
133 | /**
134 | * [30.5, 31.5) A.
135 | */
136 | D31; // this is the hard-limit for the distance between pairs
137 |
138 | /**
139 | * Cached values of this enum. Don't manipulate this array or things will burn.
140 | */
141 | public static final DistanceType[] values = values();
142 |
143 | /**
144 | * Width of a distance bin.
145 | */
146 | public static final int BIN_SIZE = 1;
147 |
148 | /**
149 | * Convert enum to distance value in Angstrom (basically the lower bound of the interval).
150 | * @return lower bound of distances landing in this bin
151 | */
152 | public int getIntRepresentation() {
153 | return ordinal() * BIN_SIZE;
154 | }
155 |
156 | /**
157 | * Convert distance in Angstrom to enum value. Will cap results into interval of possible values.
158 | * @param distance raw distance
159 | * @return the corresponding bin
160 | */
161 | public static DistanceType ofDistance(float distance) {
162 | int i = Math.round(distance / BIN_SIZE);
163 | if (i < 0) {
164 | return DistanceType.D0;
165 | } else if (i >= values.length) {
166 | return DistanceType.D31;
167 | } else {
168 | return values[i];
169 | }
170 | }
171 |
172 | /**
173 | * Convert the ordinal to enum value. Somewhat trivial. Will cap results into interval of possible values.
174 | * @param ordinal the ordinal to get
175 | * @return the corresponding bin
176 | */
177 | public static DistanceType ofIntRepresentation(int ordinal) {
178 | return values[Algebra.capToInterval(0, ordinal, values.length)];
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/strucmotif-search-core/src/main/java/org/rcsb/strucmotif/domain/motif/EnrichedMotifDefinition.java:
--------------------------------------------------------------------------------
1 | package org.rcsb.strucmotif.domain.motif;
2 |
3 | import org.rcsb.strucmotif.domain.structure.LabelAtomId;
4 | import org.rcsb.strucmotif.domain.structure.Structure;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.Objects;
9 |
10 | /**
11 | * Enriched motif definitions wrap a {@link MotifDefinition} and provide additionally access to the underlying
12 | * {@link Structure} as well as referenced residues.
13 | */
14 | public class EnrichedMotifDefinition extends MotifDefinition {
15 | private final Structure structure;
16 | private final List