Ejemplo n.º 1
0
        /// <summary>
        /// Add a ChargeGroup to the MDMolecule if not already present.
        /// </summary>
        /// <param name="chargeGroup"><see cref="ChargeGroup"/> to add</param>
        public void AddChargeGroup(ChargeGroup chargeGroup)
        {
            if (chargeGroups == null)
            {
                chargeGroups = new List <ChargeGroup>();
            }

            //Check if exists
            if (chargeGroups.Contains(chargeGroup))
            {
                Console.Out.WriteLine("Charge group: " + chargeGroup.GetNumber() + " already present in molecule: " + Id);
                return;
            }

            chargeGroups.Add(chargeGroup);
        }
Ejemplo n.º 2
0
        public void TestMDMolecule()
        {
            MDMolecule mol = new MDMolecule();

            mol.Atoms.Add(builder.NewAtom("C"));                       // 0
            mol.Atoms.Add(builder.NewAtom("C"));                       // 1
            mol.Atoms.Add(builder.NewAtom("C"));                       // 2
            mol.Atoms.Add(builder.NewAtom("C"));                       // 3
            mol.Atoms.Add(builder.NewAtom("C"));                       // 4
            mol.Atoms.Add(builder.NewAtom("C"));                       // 5

            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single); // 1
            mol.AddBond(mol.Atoms[1], mol.Atoms[2], BondOrder.Double); // 2
            mol.AddBond(mol.Atoms[2], mol.Atoms[3], BondOrder.Single); // 3
            mol.AddBond(mol.Atoms[3], mol.Atoms[4], BondOrder.Double); // 4
            mol.AddBond(mol.Atoms[4], mol.Atoms[5], BondOrder.Single); // 5
            mol.AddBond(mol.Atoms[5], mol.Atoms[0], BondOrder.Double); // 6

            //Create 2 residues
            var ac = builder.NewAtomContainer();

            ac.Atoms.Add(mol.Atoms[0]);
            ac.Atoms.Add(mol.Atoms[1]);
            ac.Atoms.Add(mol.Atoms[2]);
            Residue res1 = new Residue(ac, 0, mol);

            res1.Name = "myResidue1";
            mol.AddResidue(res1);

            var ac2 = builder.NewAtomContainer();

            ac2.Atoms.Add(mol.Atoms[3]);
            ac2.Atoms.Add(mol.Atoms[4]);
            ac2.Atoms.Add(mol.Atoms[5]);
            Residue res2 = new Residue(ac2, 1, mol);

            res2.Name = "myResidue2";
            mol.AddResidue(res2);

            //Test residue creation
            Assert.AreEqual(res1.GetParentMolecule(), mol);
            Assert.AreEqual(res2.GetParentMolecule(), mol);
            Assert.AreEqual(res1.Atoms.Count, 3);
            Assert.AreEqual(res2.Atoms.Count, 3);
            Assert.AreEqual(res1.Name, "myResidue1");
            Assert.AreEqual(res2.Name, "myResidue2");
            Assert.IsNotNull(mol.GetResidues());
            Assert.AreEqual(mol.GetResidues().Count, 2);
            Assert.AreEqual(mol.GetResidues()[0], res1);
            Assert.AreEqual(mol.GetResidues()[1], res2);

            //Create 2 chargegroups
            var ac3 = builder.NewAtomContainer();

            ac3.Atoms.Add(mol.Atoms[0]);
            ac3.Atoms.Add(mol.Atoms[1]);
            ChargeGroup chg1 = new ChargeGroup(ac3, 0, mol);

            mol.AddChargeGroup(chg1);

            var ac4 = builder.NewAtomContainer();

            ac4.Atoms.Add(mol.Atoms[2]);
            ac4.Atoms.Add(mol.Atoms[3]);
            ac4.Atoms.Add(mol.Atoms[4]);
            ac4.Atoms.Add(mol.Atoms[5]);
            ChargeGroup chg2 = new ChargeGroup(ac4, 1, mol);

            mol.AddChargeGroup(chg2);

            //Test chargegroup creation
            Assert.AreEqual(chg1.GetParentMolecule(), mol);
            Assert.AreEqual(chg2.GetParentMolecule(), mol);
            Assert.AreEqual(chg1.Atoms.Count, 2);
            Assert.AreEqual(chg2.Atoms.Count, 4);

            Assert.IsNotNull(mol.GetChargeGroups());
            Assert.AreEqual(mol.GetChargeGroups().Count, 2);
            Assert.AreEqual(mol.GetChargeGroups()[0], chg1);
            Assert.AreEqual(mol.GetChargeGroups()[1], chg2);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a benzene molecule with 2 residues and 2 charge groups
        /// </summary>
        /// <returns></returns>
        public MDMolecule MakeMDBenzene()
        {
            MDMolecule mol = new MDMolecule();

            mol.Atoms.Add(builder.NewAtom("C"));                       // 0
            mol.Atoms.Add(builder.NewAtom("C"));                       // 1
            mol.Atoms.Add(builder.NewAtom("C"));                       // 2
            mol.Atoms.Add(builder.NewAtom("C"));                       // 3
            mol.Atoms.Add(builder.NewAtom("C"));                       // 4
            mol.Atoms.Add(builder.NewAtom("C"));                       // 5

            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single); // 1
            mol.AddBond(mol.Atoms[1], mol.Atoms[2], BondOrder.Double); // 2
            mol.AddBond(mol.Atoms[2], mol.Atoms[3], BondOrder.Single); // 3
            mol.AddBond(mol.Atoms[3], mol.Atoms[4], BondOrder.Double); // 4
            mol.AddBond(mol.Atoms[4], mol.Atoms[5], BondOrder.Single); // 5
            mol.AddBond(mol.Atoms[5], mol.Atoms[0], BondOrder.Double); // 6

            //Create 2 residues
            var ac = builder.NewAtomContainer();

            ac.Atoms.Add(mol.Atoms[0]);
            ac.Atoms.Add(mol.Atoms[1]);
            ac.Atoms.Add(mol.Atoms[2]);
            Residue res1 = new Residue(ac, 0, mol);

            res1.Name = "myResidue1";
            mol.AddResidue(res1);

            var ac2 = builder.NewAtomContainer();

            ac2.Atoms.Add(mol.Atoms[3]);
            ac2.Atoms.Add(mol.Atoms[4]);
            ac2.Atoms.Add(mol.Atoms[5]);
            Residue res2 = new Residue(ac2, 1, mol);

            res2.Name = "myResidue2";
            mol.AddResidue(res2);

            //Create 2 chargegroups
            var ac3 = builder.NewAtomContainer();

            ac3.Atoms.Add(mol.Atoms[0]);
            ac3.Atoms.Add(mol.Atoms[1]);
            ChargeGroup chg1 = new ChargeGroup(ac3, 2, mol);

            chg1.SetSwitchingAtom(mol.Atoms[1]);
            mol.AddChargeGroup(chg1);

            var ac4 = builder.NewAtomContainer();

            ac4.Atoms.Add(mol.Atoms[2]);
            ac4.Atoms.Add(mol.Atoms[3]);
            ac4.Atoms.Add(mol.Atoms[4]);
            ac4.Atoms.Add(mol.Atoms[5]);
            ChargeGroup chg2 = new ChargeGroup(ac4, 3, mol);

            chg2.SetSwitchingAtom(mol.Atoms[4]);
            mol.AddChargeGroup(chg2);

            return(mol);
        }