Пример #1
0
        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;
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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]));
        }