Ejemplo n.º 1
0
		private IEnumerable<IAtomContainer> splitMolecule(IAtomContainer atomContainer, IBond bond, IDictionary<IAtom, IList<IBond>> atomBonds)
		{
			//if this bond is in a ring we have to split another bond in this ring where at least one 
			//bond is in between. Otherwise we wont have two fragments. Else normal split.

			var ret = new List<IAtomContainer>();

			//get bond energy for splitting this bond
			var currentBondEnergy = BondEnergies.Lookup(bond);			

			//bond is in a ring....so we have to split up another bond to break it
			var rings = allRings.getRings(bond);
			if (rings.getAtomContainerCount() != 0)
			{
				foreach (var bondInRing in rings.getAtomContainer(0).bonds().ToWindowsEnumerable<IBond>())
				{
					//if the bonds are the same...this wont split up the ring
					if (bondInRing == bond)
					{
						continue;
					}

					//check for already tried bonds
					var check = new BondPair(bond, bondInRing);
					if (knownBonds.Contains(check))
					{
						continue;
					}
					knownBonds.Add(new BondPair(bond, bondInRing));


					var set = new List<IAtomContainer>();
					var bondListList = new List<List<IBond>>();
					var fragWeightList = new List<Double>();

					foreach (var currentAtom in bond.atoms().ToWindowsEnumerable<IAtom>())
					{
						//List with bonds in Ring
						var partRing = new List<IBond>();
						//reset the weight because it is computed inside the traverse
						currentFragWeight = 0.0;
						//initialize new atom list
						atomList = new List<IAtom>();

						//clone current atom because a single electron is being added...homolytic cleavage
						partRing = traverse(atomBonds, currentAtom, partRing, bond, bondInRing);

						bondListList.Add(partRing);
						fragWeightList.Add(currentFragWeight);

						var temp = makeAtomContainer(currentAtom, partRing);
						//set the properties again!
						var properties = atomContainer.getProperties();
						temp.setProperties(properties);


						//*********************************************************
						//BOND ENERGY CALCULATION
						//calculate bond energy
						var currentBondEnergyRing = BondEnergies.Lookup(bondInRing);

						//*********************************************************

						//now set property
						temp = setBondEnergy(temp, (currentBondEnergyRing + currentBondEnergy));
						set.Add(temp);
					}

					//now maybe add the fragments to the list
					for (var j = 0; j < set.Count; j++)
					{
						//Render.Draw(set.getAtomContainer(j), "");
						if (set[j].getAtomCount() > 0 && set[j].getBondCount() > 0 && set[j].getAtomCount() != atomContainer.getAtomCount())
						{
							//now check the current mass
							var fragMass = getFragmentMass(set[j], fragWeightList[j]);
							//check the weight of the current fragment
							if (!isHeavyEnough(fragMass))
							{
								continue;
							}

							//returns true if isomorph
							//set the current sum formula
							var fragmentFormula = MolecularFormulaTools.GetMolecularFormula(set[j]);
							var currentSumFormula = MolecularFormulaTools.GetString(fragmentFormula);

							if (isIdentical(set[j], currentSumFormula))
							{
								continue;
							}

							//add the fragment to the return list
							ret.Add(set[j]);
						}
					}
				}
			}
			else
			{
				var set = new List<IAtomContainer>();
				var bondListList = new List<List<IBond>>();
				var fragWeightList = new List<Double>();

				//get the atoms from the splitting bond --> create 2 fragments
				foreach (var currentAtom in bond.atoms().ToWindowsEnumerable<IAtom>())
				{
					var part = new List<IBond>();
					//reset the weight because it is computed inside the traverse
					currentFragWeight = 0.0;
					//initialize new atom list
					atomList = new List<IAtom>();
					part = traverse(atomBonds, currentAtom, part, bond);
					bondListList.Add(part);

					//create Atomcontainer out of bondList        		
					var temp = makeAtomContainer(currentAtom, part);
					//set the properties again!
					var properties = atomContainer.getProperties();
					temp.setProperties(properties);
					//now calculate the correct weight subtrating the possible neutral loss mass

					fragWeightList.Add(currentFragWeight);


					//now set property: BondEnergy!
					temp = setBondEnergy(temp, currentBondEnergy);
					set.Add(temp);
				}


				//at most 2 new molecules
				for (var i = 0; i < set.Count; i++)
				{
					if (set[i].getAtomCount() > 0 && set[i].getBondCount() > 0 && set[i].getAtomCount() != atomContainer.getAtomCount())
					{
						//now check the current mass
						var fragMass = getFragmentMass(set[i], fragWeightList[i]);
						//check the weight of the current fragment
						if (!isHeavyEnough(fragMass))
						{
							continue;
						}

						//set the current sum formula
						var fragmentFormula = MolecularFormulaTools.GetMolecularFormula(set[i]);
						var currentSumFormula = MolecularFormulaTools.GetString(fragmentFormula);
						//returns true if isomorph (fast isomorph check)
						if (isIdentical(set[i], currentSumFormula))
						{
							continue;
						}

						ret.Add(set[i]);
					}
				}
			}

			return ret;
		}
Ejemplo n.º 2
0
		public static double Lookup(IBond bond)
		{
			var atoms = bond.atoms().ToWindowsEnumerable<IAtom>().ToList();

			return Lookup(atoms.First().getSymbol(), atoms.Last().getSymbol(), bond.getOrder().toString());
		}