Пример #1
0
 bool IsInChain(BondingAtom b, int parentIndex)
 {
     if (b.Element != Element.C) return false;
     if (parentIndex != 0 && b == chain[parentIndex - 1]) return true;
     if (parentIndex != chain.Length - 1 && b == chain[parentIndex + 1]) return true;
     return false;
 }
Пример #2
0
 static string AlkylSMILES(BondingAtom b, BondingAtom parent)
 {
     string smiles = b.Element.ToString();
     foreach (BondingAtom child in b)
     {
         if (child != parent) smiles += AlkylSMILES(child, b);
     }
     return smiles;
 }
Пример #3
0
 private void AddChildren(BondingAtom b, BondingAtom parent)
 {
     foreach (BondingAtom child in b)
     {
         if (child != parent)
         {
             atoms.Add(child);
             AddChildren(child, b);
         }
     }
 }
Пример #4
0
 int AlkylLength(BondingAtom b, BondingAtom parent)
 {
     foreach (BondingAtom child in b)
     {
         if (child != parent) return AlkylLength(child, b) + 1;
     }
     return 1;
 }
Пример #5
0
 public OrganicMolecule(BondingAtom a)
     : this(new Molecule(a))
 {
 }
Пример #6
0
 public OrganicMoleculeNamer(BondingAtom[] chain, Group highest)
 {
     this.chain = chain;
     this.highest = highest;
     prefixes = new Dictionary<string, List<int>>();
     suffixes = new Dictionary<string, List<int>>();
     EnumerateChain();
 }
Пример #7
0
 int LongestChildChain(BondingAtom b, BondingAtom parent)
 {
     int max = 0;
     foreach (BondingAtom child in b)
     {
         if (child != parent && child.Element == Element.C)
         {
             max = Math.Max(max, LongestChildChain(child, b) + 1);
         }
     }
     return max;
     //return b.Where(child => child != parent && child.Element == Element.C).Max<BondingAtom, int>(child => LongestChildChain(child, b) + 1);
 }
Пример #8
0
 bool IsEnd(BondingAtom b)
 {
     int bondedCInChain = 0;
     foreach (BondingAtom atom in b)
     {
         if (chain.Contains(atom)) bondedCInChain++;
     }
     return bondedCInChain < 2;
     //return b.Count(atom => chain.Contains(atom)) < 2;
 }
Пример #9
0
 bool HasNonAlkylChild(BondingAtom b, BondingAtom parent)
 {
     foreach (Bond bond in b.Bonds)
     {
         if (bond.Target != parent)
         {
             if (bond.Target.Element != Element.C || bond.Order != 1) return true;
             if (HasNonAlkylChild(bond.Target, b)) return true;
         }
     }
     return false;
     //return b.Bonds.Where(bond => bond.Target != parent).Any(
     //    bond => bond.Target.Element != Element.C || bond.Order != 1 || HasNonAlkylChild(bond.Target, b));
 }
Пример #10
0
 BondingAtom ChildWithLongestChain(BondingAtom b, BondingAtom parent)
 {
     int max = 0;
     BondingAtom maxChild = null;
     foreach (BondingAtom child in b)
     {
         if (child != parent && child.Element == Element.C)
         {
             int childChainLength = LongestChildChain(child, b) + 1;
             if (childChainLength > max) maxChild = child;
             max = Math.Max(max, childChainLength);
         }
     }
     return maxChild;
 }
Пример #11
0
 void AssignChildren(BondingAtom b, BondingAtom parent)
 {
     foreach (BondingAtom child in b)
     {
         if (child != parent && child.Element == Element.C)
         {
             if (HasNonAlkylChild(child, b))
             {
                 chain.Add(child);
                 AssignChildren(child, b);
                 return;
             }
         }
     }
     //what if all children were alkyl?
     BondingAtom child2 = ChildWithLongestChain(b, parent);
     if (child2 != null)
     {
         chain.Add(child2);
         AssignChildren(child2, b);
     }
 }
Пример #12
0
 public BondingAtom[] GetChain()
 {
     BondingAtom[] bAs = new BondingAtom[chain.Count];
     bAs[0] = chain.Find((BondingAtom b) => IsEnd(b));
     BondingAtom parent = null;
     for (int i = 1; i < bAs.Length; i++)
     {
         foreach (BondingAtom b in bAs[i - 1])
         {
             if (b.Element == Element.C && b != parent && chain.Contains(b))
             {
                 parent = bAs[i - 1];
                 bAs[i] = b;
                 break;
             }
         }
     }
     return bAs;
 }
Пример #13
0
 public Molecule(BondingAtom b)
 {
     atoms = new List<BondingAtom>();
     atoms.Add(b);
     AddChildren(b, null);
 }