public MoleculeReference AddMolecule(MoleculeReference moleculeToBeAdded, uint firstAtomId, uint connectionAtomId, BondMultiplicity bondMultiplicity = BondMultiplicity.Single) { return(AddMolecule(moleculeToBeAdded, firstAtomId, connectionAtomId, out _, bondMultiplicity)); }
public static MoleculeReference ConnectTo(this MoleculeReference moleculeReference, MoleculeReference otherReference, BondMultiplicity bondMultiplicity = BondMultiplicity.Single) { if (!moleculeReference.IsInitialized) { throw new InvalidOperationException("Cannot add atoms. Molecule reference is not initialized"); } if (!otherReference.IsInitialized) { throw new InvalidOperationException("Cannot add atoms. Side chain molecule reference is not initialized"); } var lastAtomInOtherReference = otherReference.Molecule.GetAtom(otherReference.LastAtomId); var matchingConnectionAtom = moleculeReference.Molecule.Atoms .SingleOrDefault(a => a.Equals(lastAtomInOtherReference)); if (matchingConnectionAtom == null) { moleculeReference.Molecule.AddMolecule(otherReference, moleculeReference.FirstAtomId, moleculeReference.LastAtomId, bondMultiplicity); } else { var connectionAtomVertexId = moleculeReference.Molecule.MoleculeStructure.Vertices .Single(v => v.Object.Equals(matchingConnectionAtom)); moleculeReference.Molecule.ConnectAtoms(moleculeReference.LastAtomId, connectionAtomVertexId.Id, bondMultiplicity); } return(moleculeReference); }
public static IEnumerable <SimpleBond> CreateBonds(Atom atom1, Atom atom2, BondMultiplicity bondMultiplicity) { if (atom1 is AtomWithOrbitals && atom2 is AtomWithOrbitals) { return(CreateOrbitalBonds((AtomWithOrbitals)atom1, (AtomWithOrbitals)atom2, (int)bondMultiplicity)); } return(CreateSimpleBonds(atom1, atom2, (int)bondMultiplicity)); }
public void ConnectAtoms(uint atomId1, uint atomId2, BondMultiplicity bondMultiplicity = BondMultiplicity.Single) { var atom1 = GetAtom(atomId1); var atom2 = GetAtom(atomId2); var bonds = AtomConnector.CreateBonds(atom1, atom2, bondMultiplicity); foreach (var bond in bonds) { var edge = (Edge <SimpleBond>)MoleculeStructure.ConnectVertices(atomId1, atomId2); edge.Object = bond; } }
public static MoleculeReference AddSideChain(this MoleculeReference moleculeReference, MoleculeReference sideChainReference, BondMultiplicity bondMultiplicity = BondMultiplicity.Single) { if (!moleculeReference.IsInitialized) { throw new InvalidOperationException("Cannot add atoms. Molecule reference is not initialized"); } moleculeReference.Molecule.AddMolecule(sideChainReference, moleculeReference.FirstAtomId, moleculeReference.LastAtomId, bondMultiplicity); return(moleculeReference); }
public uint AddAtom(Atom atom, uint existingAtomId = uint.MaxValue, BondMultiplicity bondMultiplicity = BondMultiplicity.Single) { // If no atoms in the molecule yet, just add the atom if (!MoleculeStructure.Vertices.Any()) { var firstVertex = new Vertex <Atom>(MoleculeStructure.GetUnusedVertexId()) { Object = atom }; MoleculeStructure.AddVertex(firstVertex); return(firstVertex.Id); } if (!MoleculeStructure.HasVertex(existingAtomId)) { throw new KeyNotFoundException("Adding atom to molecule failed, because the reference to an existing atom was not found"); } var existingAtom = MoleculeStructure.GetVertexFromId(existingAtomId).Object; var vertex = new Vertex <Atom>(MoleculeStructure.GetUnusedVertexId()) { Object = atom }; MoleculeStructure.AddVertex(vertex); var bonds = AtomConnector.CreateBonds(atom, existingAtom, bondMultiplicity); foreach (var bond in bonds) { var edge = new Edge <SimpleBond>(MoleculeStructure.GetUnusedEdgeId(), existingAtomId, vertex.Id) { Object = bond }; MoleculeStructure.AddEdge(edge); } return(vertex.Id); }
public MoleculeReference AddMolecule(MoleculeReference moleculeToBeAdded, uint firstAtomId, uint connectionAtomId, out MoleculeReference convertedInputMoleculeReference, BondMultiplicity bondMultiplicity = BondMultiplicity.Single) { var mergeInfo = MoleculeStructure.AddGraph(moleculeToBeAdded.Molecule.MoleculeStructure); var vertex1 = connectionAtomId; var vertex2 = mergeInfo.VertexIdMap[moleculeToBeAdded.FirstAtomId]; var atom1 = MoleculeStructure.GetVertexFromId(vertex1).Object; var atom2 = MoleculeStructure.GetVertexFromId(vertex2).Object; var bonds = AtomConnector.CreateBonds(atom1, atom2, bondMultiplicity); foreach (var bond in bonds) { var edge = (Edge <SimpleBond>)MoleculeStructure.ConnectVertices(vertex1, vertex2); edge.Object = bond; } convertedInputMoleculeReference = new MoleculeReference(this, moleculeToBeAdded.VertexIds.Select(oldVertexId => mergeInfo.VertexIdMap[oldVertexId]), mergeInfo.VertexIdMap[moleculeToBeAdded.FirstAtomId], mergeInfo.VertexIdMap[moleculeToBeAdded.LastAtomId]); return(new MoleculeReference(this, firstAtomId, mergeInfo.VertexIdMap[moleculeToBeAdded.LastAtomId])); }
public static MoleculeReference AddToCurrentAtom(this MoleculeReference moleculeReference, ElementName element, BondMultiplicity bondMultiplicity) { if (!moleculeReference.IsInitialized) { throw new InvalidOperationException("Cannot add atoms. Molecule reference is not initialized"); } var atom = Atom.FromStableIsotope(element); moleculeReference.Molecule.AddAtom(atom, moleculeReference.LastAtomId, bondMultiplicity); return(moleculeReference); }
public static MoleculeReference Add(this MoleculeReference moleculeReference, ElementName element, BondMultiplicity bondMultiplicity) { var lastAtomId = moleculeReference.LastAtomId; var atom = Atom.FromStableIsotope(element); lastAtomId = moleculeReference.Molecule.AddAtom(atom, lastAtomId); if (!moleculeReference.IsInitialized) { moleculeReference.FirstAtomId = lastAtomId; } return(new MoleculeReference(moleculeReference.Molecule, moleculeReference.FirstAtomId, lastAtomId)); }