/// <summary> /// Method that assign properties to an atom given a particular atomType. /// An <see cref="ArgumentException"/> is thrown if the given <see cref="IAtomType"/> /// is null. <b>This method overwrites non-null values.</b> /// </summary> /// <param name="atom">Atom to configure</param> /// <param name="atomType">AtomType. Must not be null.</param> public static void Configure(IAtom atom, IAtomType atomType) { if (atomType == null) { throw new ArgumentNullException(nameof(atomType)); } if (string.Equals("X", atomType.AtomTypeName, StringComparison.Ordinal)) { atom.AtomTypeName = "X"; return; } // we set the atom type name, but nothing else atom.AtomTypeName = atomType.AtomTypeName; // configuring atom type information is not really valid // for pseudo atoms - first because they basically have no // type information and second because they may have information // associated with them from another context, which should not be // overwritten. So we only do the stuff below if we have a non pseudoatom // // a side effect of this is that it is probably not valid to get the atom // type of a pseudo atom. I think this is OK, since you can always check // whether an atom is a pseudo atom without looking at its atom type if (!(atom is IPseudoAtom)) { atom.Symbol = atomType.Symbol; atom.MaxBondOrder = atomType.MaxBondOrder; atom.BondOrderSum = atomType.BondOrderSum; atom.CovalentRadius = atomType.CovalentRadius; atom.Valency = atomType.Valency; atom.FormalCharge = atomType.FormalCharge; atom.Hybridization = atomType.Hybridization; atom.FormalNeighbourCount = atomType.FormalNeighbourCount; atom.IsHydrogenBondAcceptor = atomType.IsHydrogenBondAcceptor; atom.IsHydrogenBondDonor = atomType.IsHydrogenBondDonor; var constant = atomType.GetProperty <int?>(CDKPropertyName.ChemicalGroupConstant); if (constant != null) { atom.SetProperty(CDKPropertyName.ChemicalGroupConstant, constant); } if (atomType.IsAromatic) { atom.IsAromatic = atomType.IsAromatic; } object color = atomType.GetProperty <object>(CDKPropertyName.Color); if (color != null) { atom.SetProperty(CDKPropertyName.Color, color); } atom.AtomicNumber = atomType.AtomicNumber; if (atomType.ExactMass != null) { atom.ExactMass = atomType.ExactMass; } } }
void Main() { IAtom atom = null; #region atom.SetProperty(MarkedElement.IdKey, "my_atm_id"); atom.SetProperty(MarkedElement.ClassKey, "h_donor"); atom.SetProperty(MarkedElement.ClassKey, "h_acceptor"); #endregion }
public object Visit(ASTReaction node, object data) { IAtomContainer query = new QueryAtomContainer(builder); for (int grpIdx = 0; grpIdx < node.JjtGetNumChildren(); grpIdx++) { int rollback = query.Atoms.Count; ASTGroup group = (ASTGroup)node.JjtGetChild(grpIdx); group.JjtAccept(this, query); // fill in the roles for newly create atoms if (group.Role != ReactionRoles.Any) { IQueryAtom roleQueryAtom = null; ReactionRole?role = null; // use single instances switch (group.Role) { case ReactionRoles.Reactant: roleQueryAtom = ReactionRoleQueryAtom.RoleReactant; role = ReactionRole.Reactant; break; case ReactionRoles.Agent: roleQueryAtom = ReactionRoleQueryAtom.RoleAgent; role = ReactionRole.Agent; break; case ReactionRoles.Product: roleQueryAtom = ReactionRoleQueryAtom.RoleProduct; role = ReactionRole.Product; break; } if (roleQueryAtom != null) { while (rollback < query.Atoms.Count) { IAtom org = query.Atoms[rollback]; IAtom rep = LogicalOperatorAtom.And(roleQueryAtom, (IQueryAtom)org); // ensure AAM is propagated rep.SetProperty(CDKPropertyName.AtomAtomMapping, org.GetProperty <int?>(CDKPropertyName.AtomAtomMapping)); rep.SetProperty(CDKPropertyName.ReactionRole, role); AtomContainerManipulator.ReplaceAtomByAtom(query, org, rep); rollback++; } } } } return(query); }
public void TestAtomValueLine() { IAtom carbon = builder.NewAtom("C"); carbon.SetProperty(CDKPropertyName.Comment, "Carbon comment"); IAtom oxygen = builder.NewAtom("O"); oxygen.SetProperty(CDKPropertyName.Comment, "Oxygen comment"); IBond bond = builder.NewBond(carbon, oxygen, BondOrder.Double); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(oxygen); molecule.Atoms.Add(carbon); molecule.Bonds.Add(bond); StringWriter writer = new StringWriter(); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("V 1 Oxygen comment") != -1); Assert.IsTrue(writer.ToString().IndexOf("V 2 Carbon comment") != -1); }
private static void MakeReferencesExplicitForAtom(IAtom atom) { int selfCounter = 0; atom.SetProperty(prefix + ":self:" + selfCounter++, "chemical:atom"); MakeReferencesExplicitForElement(atom); }
/// <summary> /// Assigns an atom type to an atom /// </summary> /// <param name="atom">The atom to be aasigned</param> /// <param name="ID">the atom type id</param> /// <exception cref="NoSuchAtomTypeException"> atomType is not known</exception> /// <returns>the assigned atom</returns> private IAtom SetAtom(IAtom atom, string ID) { IAtomType at = GetAtomType(ID); if (atom.Symbol == null) { atom.Symbol = at.Symbol; } atom.AtomTypeName = at.AtomTypeName; atom.FormalNeighbourCount = at.FormalNeighbourCount; string key = "vdw" + ID; var data = (System.Collections.IList)parameterSet[key]; double value = (double)data[0]; key = "charge" + ID; if (parameterSet.ContainsKey(key)) { data = (System.Collections.IList)parameterSet[key]; value = (double)data[0]; atom.Charge = value; } var color = at.GetProperty <object>(CDKPropertyName.Color); if (color != null) { atom.SetProperty(CDKPropertyName.Color, color); } if (at.AtomicNumber != 0) { atom.AtomicNumber = at.AtomicNumber; } if (at.ExactMass > 0.0) { atom.ExactMass = at.ExactMass; } return(atom); }
/// <summary> /// Configures an atom. Finds the correct element type by looking at the Atom's /// atom type name, and if that fails, picks the first atom type matching /// the Atom's element symbol.. /// </summary> /// <param name="atom">The atom to be configured</param> /// <returns>The configured atom</returns> /// <exception cref="CDKException">when it could not recognize and configure the <see cref="IAtom"/></exception> public IAtom Configure(IAtom atom) { if (atom is IPseudoAtom) { // do not try to configure PseudoAtom's return(atom); } try { IAtomType atomType; if (string.IsNullOrEmpty(atom.AtomTypeName)) { atomType = GetAtomTypes(atom.Symbol).First(); } else { atomType = GetAtomType(atom.AtomTypeName); } atom.Symbol = atomType.Symbol; atom.MaxBondOrder = atomType.MaxBondOrder; atom.BondOrderSum = atomType.BondOrderSum; atom.CovalentRadius = atomType.CovalentRadius; atom.Hybridization = atomType.Hybridization; atom.SetProperty(CDKPropertyName.Color, atomType.GetProperty <object>(CDKPropertyName.Color)); atom.AtomicNumber = atomType.AtomicNumber; atom.ExactMass = atomType.ExactMass; } catch (CDKException) { throw; } catch (Exception exception) { throw new CDKException(exception.Message, exception); } return(atom); }
public static void SetCIPDescriptor(this IAtom o, string chirality) => o.SetProperty(CIPDescriptorPropertyKey, chirality);
/// <summary> /// Method assigns atom types to atoms (calculates sssr and aromaticity) /// </summary> /// <returns>sssrf set</returns> /// <exception cref="CDKException"> Problems detecting aromaticity or making hose codes.</exception> public IRingSet AssignAtomTyps(IAtomContainer molecule) { IAtom atom = null; string hoseCode = ""; HOSECodeGenerator hcg = new HOSECodeGenerator(); int NumberOfRingAtoms = 0; IRingSet ringSetMolecule = Cycles.FindSSSR(molecule).ToRingSet(); bool isInHeteroRing = false; try { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); Aromaticity.CDKLegacy.Apply(molecule); } catch (Exception cdk1) { throw new CDKException("AROMATICITYError: Cannot determine aromaticity due to: " + cdk1.Message, cdk1); } for (int i = 0; i < molecule.Atoms.Count; i++) { atom = molecule.Atoms[i]; if (ringSetMolecule.Contains(atom)) { NumberOfRingAtoms = NumberOfRingAtoms + 1; atom.IsInRing = true; atom.IsAliphatic = false; var ringSetA = ringSetMolecule.GetRings(atom).ToList(); RingSetManipulator.Sort(ringSetA); IRing sring = (IRing)ringSetA[ringSetA.Count - 1]; atom.SetProperty("RING_SIZE", sring.RingSize); foreach (var ring in ringSetA) { if (IsHeteroRingSystem(ring)) { break; } } } else { atom.IsAliphatic = true; atom.IsInRing = false; isInHeteroRing = false; } atom.SetProperty("MAX_BOND_ORDER", molecule.GetMaximumBondOrder(atom).Numeric()); try { hoseCode = hcg.GetHOSECode(molecule, atom, 3); //Debug.WriteLine("HOSECODE GENERATION: ATOM "+i+" HoseCode: "+hoseCode+" "); } catch (CDKException ex1) { Console.Out.WriteLine("Could not build HOSECode from atom " + i + " due to " + ex1.ToString()); throw new CDKException("Could not build HOSECode from atom " + i + " due to " + ex1.ToString(), ex1); } try { ConfigureAtom(atom, hoseCode, isInHeteroRing); } catch (CDKException ex2) { Console.Out.WriteLine("Could not final configure atom " + i + " due to " + ex2.ToString()); throw new CDKException("Could not final configure atom due to problems with force field", ex2); } } // IBond[] bond = molecule.Bonds; string bondType; foreach (var bond in molecule.Bonds) { //Debug.WriteLine("bond[" + i + "] properties : " + molecule.Bonds[i].GetProperties()); bondType = "0"; if (bond.Order == BondOrder.Single) { if ((bond.Begin.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) && ((bond.End.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) || (bond.End.AtomTypeName.Equals("C=", StringComparison.Ordinal)))) { bondType = "1"; } if ((bond.Begin.AtomTypeName.Equals("C=", StringComparison.Ordinal)) && ((bond.End.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) || (bond.End.AtomTypeName.Equals("C=", StringComparison.Ordinal)))) { bondType = "1"; } if ((bond.Begin.AtomTypeName.Equals("Csp", StringComparison.Ordinal)) && (bond.End.AtomTypeName.Equals("Csp", StringComparison.Ordinal))) { bondType = "1"; } } // molecule.Bonds[i].SetProperty("MMFF94 bond type", bondType); bond.SetProperty("MMFF94 bond type", bondType); //Debug.WriteLine("bond[" + i + "] properties : " + molecule.Bonds[i].GetProperties()); } return(ringSetMolecule); }
public InvPair(long current, IAtom atom) { Curr = current; Atom = atom; atom.SetProperty(InvariancePairPropertyKey, this); }
public void Commit() { Atom.SetProperty(CanonicalLabelPropertyKey, Curr); }