/// <summary> /// The cycle path is accepted if it does not have chord. /// </summary> /// <param name="path">a path</param> /// <param name="graph">the adjacency of atoms</param> /// <returns>accept the path as unchorded</returns> private static bool Accept(int[] path, int[][] graph) { BitArray vertices = new BitArray(0); foreach (var v in path) { BitArrays.SetValue(vertices, v, true); } for (int j = 1; j < path.Length; j++) { int v = path[j]; int prev = path[j - 1]; int next = path[(j + 1) % (path.Length - 1)]; foreach (var w in graph[v]) { // chord found if (w != prev && w != next && BitArrays.GetValue(vertices, w)) { return(false); } } } return(true); }
public override bool Matches(IAtom atom) { if (!((IQueryAtom)query.Atoms[0]).Matches(atom)) { return(false); } if (query.Atoms.Count == 1) { return(true); } IAtomContainer target = Invariants(atom).Target; if (!cache.TryGetValue(target, out BitArray v)) { BitArray hits = new BitArray(0); foreach (var mapping in Pattern.CreateSubstructureFinder(query).MatchAll(target)) { BitArrays.SetValue(hits, mapping[0], true); } v = hits; cache[target] = v; } return(BitArrays.GetValue(v, target.Atoms.IndexOf(atom))); }
/// <summary> /// Convert a mapping to a bitset. /// </summary> /// <param name="mapping">an atom mapping</param> /// <returns>a bit set of the mapped vertices (values in array)</returns> private static BitArray ToBitArray(int[] mapping) { BitArray hits = new BitArray(0); foreach (var v in mapping) { BitArrays.SetValue(hits, v, true); } return(hits); }
public static BitArray AsBitSet(params int[] xs) { BitArray bs = new BitArray(0); foreach (var x in xs) { BitArrays.SetValue(bs, x, true); } return(bs); }
public bool this[int index] { get { return(BitArrays.GetValue(bitset, index)); } set { BitArrays.SetValue(bitset, index, value); } }
public object Visit(ASTChirality node, object data) { var atom = new ChiralityAtom(builder) { IsClockwise = node.IsClockwise, IsUnspecified = node.IsUnspecified }; BitArrays.SetValue(tetrahedral, query.Atoms.Count, true); return(atom); }
/// <summary> /// Get the atoms in the target molecule that match the query pattern. /// <para> /// Since there may be multiple matches, the /// return value is a List of List objects. Each List object contains the unique set of indices of the atoms in the /// target molecule, that match the query pattern /// </para> /// </summary> /// <returns>A List of List of atom indices in the target molecule</returns> public IEnumerable <IReadOnlyList <int> > GetUniqueMatchingAtoms() { var atomSets = new HashSet <BitArray>(BitArrays.EqualityComparer); foreach (var mapping in mappings) { BitArray atomSet = new BitArray(0); foreach (var x in mapping) { BitArrays.SetValue(atomSet, x, true); } if (atomSets.Add(atomSet)) { yield return(mapping); } } yield break; }
public void TestGetBitFingerprint() { Assert.IsTrue(trivialMol != null); var circ = new CircularFingerprinter(); var result = circ.GetBitFingerprint(trivialMol); BitArray wantBits = new BitArray(0), gotBits = result.AsBitSet(); int[] REQUIRE_BITS = { 19, 152, 293, 340, 439, 480, 507, 726, 762, 947, 993 }; foreach (var b in REQUIRE_BITS) { BitArrays.SetValue(wantBits, b, true); } if (!BitArrays.Equals(wantBits, gotBits)) { throw new CDKException("Got " + gotBits + ", wanted " + wantBits); } }
/// <summary> /// Check if the atom at index <paramref name="v"/> is a member of a small ring /// (n=3). This is the only time a 3 valent nitrogen is allowed by InChI to /// be potentially stereogenic. /// </summary> /// <param name="v">atom index</param> /// <returns>the atom is a member of a 3 member ring</returns> private bool InThreeMemberRing(int v) { var adj = new BitArray(0); foreach (var w in g[v]) { BitArrays.SetValue(adj, w, true); } // is a neighbors neighbor adjacent? foreach (var w in g[v]) { foreach (var u in g[w]) { if (BitArrays.GetValue(adj, u)) { return(true); } } } return(false); }
/// <summary> /// Adds a new node to the CDKRGraph. /// <param name="newNode">The node to add to the graph</param> /// </summary> public void AddNode(CDKRNode newNode) { Graph.Add(newNode); BitArrays.SetValue(GraphBitSet, Graph.Count - 1, true); }
public void Set(int i) { BitArrays.SetValue(bitset, i, true); }