public PriceGridViewModel(IPriceGridView view)
        {
            View = view;

            Bonds = new Models.Bonds();
            Bonds.Add(new Bond() { ISIN = "Bond1", Price = 100.0, Timestamp = DateTime.Now, YTM = 1.0, Duration = 10.0 });
            Bonds.Add(new Bond() { ISIN = "Bond2", Price = 66.0, Timestamp = DateTime.Now, YTM = 3.0, Duration = 33.0 });
            Bonds.Add(new Bond() { ISIN = "Bond3", Price = 111.0, Timestamp = DateTime.Now, YTM = 6.0, Duration = 2.0 });
            Bonds.Add(new Bond() { ISIN = "Bond4", Price = 123.0, Timestamp = DateTime.Now, YTM = 2.0, Duration = 77.0 });
            Bonds.Add(new Bond() { ISIN = "Bond5", Price = 90.0, Timestamp = DateTime.Now, YTM = 9.0, Duration = 8.0 });

            View.Model = this;
        }
 internal bool Delete(Bonds Bonds)
 {
     try
     {
         FinancialPlanner.Common.JSONSerialization jsonSerialization = new FinancialPlanner.Common.JSONSerialization();
         string          apiurl          = Program.WebServiceUrl + "/" + DELETE_Bonds_API;
         RestAPIExecutor restApiExecutor = new RestAPIExecutor();
         var             restResult      = restApiExecutor.Execute <Bonds>(apiurl, Bonds, "POST");
         return(true);
     }
     catch (Exception ex)
     {
         StackTrace st = new StackTrace();
         StackFrame sf = st.GetFrame(0);
         MethodBase currentMethodName = sf.GetMethod();
         LogDebug(currentMethodName.Name, ex);
         return(false);
     }
 }
示例#3
0
        public void showPortfolio()
        {
            //Arrange
            double stocksBal  = 5500.00;
            double bondsBal   = 3450.00;
            double annuityBal = 820.00;

            Annuity ann  = new Annuity();
            Stocks  sto  = new Stocks();
            Bonds   bond = new Bonds();

            //Act
            ann.Buy(annuityBal);
            sto.Buy(stocksBal);
            bond.Buy(bondsBal);
            double actualBal = ann.GetShares + sto.GetShares + bond.GetShares;

            // assert
            Assert.AreEqual(actualBal, 9770.00);
        }
示例#4
0
        public void ScaleToAverageBondLength(double newLength, Model model)
        {
            if (Bonds.Any())
            {
                double averageBondLength = MeanBondLength;

                if (averageBondLength != 0 && newLength > 0)
                {
                    double scale = newLength / averageBondLength;

                    foreach (Atom atom in Atoms)
                    {
                        atom.Position = new Point(atom.Position.X * scale, atom.Position.Y * scale);
                    }
                }
                foreach (Molecule child in Molecules)
                {
                    child.ScaleToAverageBondLength(newLength, model);
                }
            }
        }
示例#5
0
        public CompassPoints GetDefaultHOrientation()
        {
            if (ImplicitHydrogenCount >= 1)
            {
                if (!Bonds.Any())
                {
                    return(CompassPoints.East);
                }
                else if (Bonds.Count() == 1)
                {
                    var angle = Vector.AngleBetween(BasicGeometry.ScreenNorth,
                                                    Bonds.First().OtherAtom(this).Position - Position);
                    int clockDirection = BasicGeometry.SnapToClock(angle);

                    if (clockDirection == 0 || clockDirection == 6)
                    {
                        return(CompassPoints.East);
                    }
                    else if (clockDirection >= 6 && clockDirection <= 11)
                    {
                        return(CompassPoints.East);
                    }
                    else
                    {
                        return(CompassPoints.West);
                    }
                }
                else
                {
                    double baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth,
                                                             BalancingVector(true));

                    return(BasicGeometry.SnapTo4NESW(baFromNorth));
                }
            }
            return(CompassPoints.East);
        }
示例#6
0
    void GetBondsDynamic(int frame)
    {
        //ThisFile.GetComponent<ThisFileInfo>().Bonds[frame].Clear();

        for (int i = 0; i < top.NATOM; i++)
        {
            for (int j = 0; j < i; j++)
            {
                float distance = Vector3.Distance(new Vector3(molecule[frame, i].x, molecule[frame, i].y, molecule[frame, i].z),
                                                  new Vector3(molecule[frame, j].x, molecule[frame, j].y, molecule[frame, j].z)) * 100; // unit conversion

                bool bondExists = CheckBondDyn(molecule[frame, i].element,
                                               molecule[frame, j].element,
                                               distance);
                if (bondExists)
                {
                    Bonds temp = new Bonds();
                    temp.Constructor(i, j);
                    temp.distance = distance;
                    ThisFile.GetComponent <ThisFileInfo>().Bonds[frame].Add(temp);
                }
            }
        }
    }
示例#7
0
        public void Delete(Bonds Bonds)
        {
            try
            {
                string clientName = DataBase.DBService.ExecuteCommandScalar(string.Format(SELECT_ID, Bonds.Id));

                DataBase.DBService.BeginTransaction();
                DataBase.DBService.ExecuteCommandString(string.Format(DELETE_Bonds,
                                                                      Bonds.Id), true);

                Activity.ActivitiesService.Add(ActivityType.DeleteBonds, EntryStatus.Success,
                                               Source.Server, Bonds.UpdatedByUserName, Bonds.CompanyName, Bonds.MachineName);
                DataBase.DBService.CommitTransaction();
            }
            catch (Exception ex)
            {
                DataBase.DBService.RollbackTransaction();
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                MethodBase currentMethodName = sf.GetMethod();
                LogDebug(currentMethodName.Name, ex);
                throw ex;
            }
        }
示例#8
0
        public Bonds Get(int id)
        {
            try
            {
                Logger.LogInfo("Get: Bonds by id process start");
                Bonds Bonds = new Bonds();

                DataTable dtAppConfig = DataBase.DBService.ExecuteCommand(string.Format(SELECT_ID, id));
                foreach (DataRow dr in dtAppConfig.Rows)
                {
                    Bonds = convertToBonds(dr);
                }
                Logger.LogInfo("Get: Bonds by id process completed");
                return(Bonds);
            }
            catch (Exception ex)
            {
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                MethodBase currentMethodName = sf.GetMethod();
                LogDebug(currentMethodName.Name, ex);
                return(null);
            }
        }
示例#9
0
        private Bonds convertToBonds(DataRow dr)
        {
            Bonds bonds = new Bonds();

            bonds.Id                   = dr.Field <int>("ID");
            bonds.Pid                  = dr.Field <int>("PID");
            bonds.InvesterName         = dr.Field <string>("InvesterName");
            bonds.CompanyName          = dr.Field <string>("CompanyName");
            bonds.FolioNo              = dr.Field <string>("FolioNo");
            bonds.FaceValue            = float.Parse(dr["FaceValue"].ToString());
            bonds.Rate                 = float.Parse(dr["Rate"].ToString());
            bonds.NoOfBond             = dr.Field <int>("NoOfBond");
            bonds.CurrentValue         = Double.Parse(dr["CurrentValue"].ToString());
            bonds.GoalId               = dr.Field <int>("GoalId");
            bonds.MaturityDate         = dr.Field <DateTime>("MaturityDate");
            bonds.UpdatedBy            = dr.Field <int>("UpdatedBy");
            bonds.UpdatedOn            = dr.Field <DateTime>("UpdatedOn");
            bonds.UpdatedByUserName    = dr.Field <string>("UpdatedByUserName");
            bonds.UpdatedBy            = dr.Field <int>("UpdatedBy");
            bonds.UpdatedOn            = dr.Field <DateTime>("UpdatedOn");
            bonds.UpdatedByUserName    = dr.Field <string>("UpdatedByUserName");
            bonds.InvestmentReturnRate = float.Parse(dr["InvestmentReturnRate"].ToString());
            return(bonds);
        }
示例#10
0
        public void Update(Bonds Bonds)
        {
            try
            {
                string clientName = DataBase.DBService.ExecuteCommandScalar(string.Format(SELECT_ID, Bonds.Id));

                DataBase.DBService.BeginTransaction();
                DataBase.DBService.ExecuteCommandString(string.Format(UPDATE_Bonds,
                                                                      Bonds.InvesterName,
                                                                      Bonds.CompanyName,
                                                                      Bonds.FolioNo,
                                                                      Bonds.Rate,
                                                                      Bonds.NoOfBond,
                                                                      Bonds.FaceValue,
                                                                      Bonds.CurrentValue,
                                                                      Bonds.MaturityDate.ToString("yyyy-MM-dd hh:mm:ss"),
                                                                      (Bonds.GoalId == null) ? null : Bonds.GoalId.Value.ToString(),
                                                                      Bonds.UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"),
                                                                      Bonds.UpdatedBy,
                                                                      Bonds.InvestmentReturnRate,
                                                                      Bonds.Id), true);

                Activity.ActivitiesService.Add(ActivityType.UpdateBonds, EntryStatus.Success,
                                               Source.Server, Bonds.UpdatedByUserName, Bonds.CompanyName, Bonds.MachineName);
                DataBase.DBService.CommitTransaction();
            }
            catch (Exception ex)
            {
                DataBase.DBService.RollbackTransaction();
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                MethodBase currentMethodName = sf.GetMethod();
                LogDebug(currentMethodName.Name, ex);
                throw ex;
            }
        }
示例#11
0
        static Universe BuildUnion(Universe univ1, Universe univ2)
        {
            Universe univ = new Universe();

            Atoms atoms = new Atoms(univ);

            //int maxresi = int.MinValue;
            //foreach(var atom in univ1.atoms)
            //{
            //    if(atom._ResidueId != null)
            //        maxresi = Math.Max(maxresi, atom._ResidueId.Value);
            //    atoms.Add(atom);
            //}
            //foreach(var atom in univ2.atoms)
            //{
            //    if(atom._ResidueId != null)
            //        atom._ResidueId = (atom._ResidueId + maxresi + 100);
            //    atoms.Add(atom);
            //}
            foreach (var atom in univ1.atoms)
            {
                atoms.Add(atom);
            }
            foreach (var atom in univ2.atoms)
            {
                atoms.Add(atom);
            }

            Bonds bonds = new Bonds();

            foreach (var bond in univ1.bonds)
            {
                bonds.Add(bond);
                Atom atom0 = bond.atoms[0];
                Atom atom1 = bond.atoms[1];
                HDebug.Assert(atom0.Bonds.Contains(bond)); HDebug.Assert(atom0.Inter123.Contains(atom1)); HDebug.Assert(atom0.Inter12.Contains(atom1));
                HDebug.Assert(atom1.Bonds.Contains(bond)); HDebug.Assert(atom1.Inter123.Contains(atom0)); HDebug.Assert(atom1.Inter12.Contains(atom0));
            }
            foreach (var bond in univ2.bonds)
            {
                bonds.Add(bond);
                Atom atom0 = bond.atoms[0];
                Atom atom1 = bond.atoms[1];
                HDebug.Assert(atom0.Bonds.Contains(bond)); HDebug.Assert(atom0.Inter123.Contains(atom1)); HDebug.Assert(atom0.Inter12.Contains(atom1));
                HDebug.Assert(atom1.Bonds.Contains(bond)); HDebug.Assert(atom1.Inter123.Contains(atom0)); HDebug.Assert(atom1.Inter12.Contains(atom0));
            }

            Angles angles = new Angles();

            foreach (Angle angle in univ1.angles)
            {
                angles.Add(angle);
                Atom atom0 = angle.atoms[0];
                Atom atom1 = angle.atoms[1];
                Atom atom2 = angle.atoms[2];
                HDebug.Assert(atom0.Angles.Contains(angle)); HDebug.Assert(atom0.Inter123.Contains(atom1)); HDebug.Assert(atom0.Inter123.Contains(atom2));
                HDebug.Assert(atom1.Angles.Contains(angle)); HDebug.Assert(atom1.Inter123.Contains(atom2)); HDebug.Assert(atom1.Inter123.Contains(atom0));
                HDebug.Assert(atom2.Angles.Contains(angle)); HDebug.Assert(atom2.Inter123.Contains(atom0)); HDebug.Assert(atom2.Inter123.Contains(atom1));
            }
            foreach (Angle angle in univ2.angles)
            {
                angles.Add(angle);
                Atom atom0 = angle.atoms[0];
                Atom atom1 = angle.atoms[1];
                Atom atom2 = angle.atoms[2];
                HDebug.Assert(atom0.Angles.Contains(angle)); HDebug.Assert(atom0.Inter123.Contains(atom1)); HDebug.Assert(atom0.Inter123.Contains(atom2));
                HDebug.Assert(atom1.Angles.Contains(angle)); HDebug.Assert(atom1.Inter123.Contains(atom2)); HDebug.Assert(atom1.Inter123.Contains(atom0));
                HDebug.Assert(atom2.Angles.Contains(angle)); HDebug.Assert(atom2.Inter123.Contains(atom0)); HDebug.Assert(atom2.Inter123.Contains(atom1));
            }

            Dihedrals dihedrals = new Dihedrals();

            foreach (Dihedral dihedral in univ1.dihedrals)
            {
                dihedrals.Add(dihedral);
                HDebug.Assert(dihedral.atoms[0].Dihedrals.Contains(dihedral));
                HDebug.Assert(dihedral.atoms[1].Dihedrals.Contains(dihedral));
                HDebug.Assert(dihedral.atoms[2].Dihedrals.Contains(dihedral));
                HDebug.Assert(dihedral.atoms[3].Dihedrals.Contains(dihedral));
            }
            foreach (Dihedral dihedral in univ2.dihedrals)
            {
                dihedrals.Add(dihedral);
                HDebug.Assert(dihedral.atoms[0].Dihedrals.Contains(dihedral));
                HDebug.Assert(dihedral.atoms[1].Dihedrals.Contains(dihedral));
                HDebug.Assert(dihedral.atoms[2].Dihedrals.Contains(dihedral));
                HDebug.Assert(dihedral.atoms[3].Dihedrals.Contains(dihedral));
            }

            Impropers impropers = new Impropers();

            foreach (var improper in univ1.impropers)
            {
                impropers.Add(improper);
                HDebug.Assert(improper.atoms[0].Impropers.Contains(improper));
                HDebug.Assert(improper.atoms[1].Impropers.Contains(improper));
                HDebug.Assert(improper.atoms[2].Impropers.Contains(improper));
                HDebug.Assert(improper.atoms[3].Impropers.Contains(improper));
            }
            foreach (var improper in univ2.impropers)
            {
                impropers.Add(improper);
                HDebug.Assert(improper.atoms[0].Impropers.Contains(improper));
                HDebug.Assert(improper.atoms[1].Impropers.Contains(improper));
                HDebug.Assert(improper.atoms[2].Impropers.Contains(improper));
                HDebug.Assert(improper.atoms[3].Impropers.Contains(improper));
            }

            Nonbonded14s nonbonded14s = new Nonbonded14s();

            nonbonded14s.Build(atoms);

            Pdb pdb;

            {
                List <Pdb.Element> elements = new List <Pdb.Element>();
                elements.AddRange(univ1.pdb.atoms);
                elements.AddRange(univ2.pdb.atoms);
                pdb = new Pdb(elements);
            }

            //Universe univ = new Universe();
            univ.pdb = pdb;
            univ.refs.Add("pdb", pdb);
            univ.atoms     = atoms;
            univ.bonds     = bonds;
            univ.angles    = angles;
            univ.dihedrals = dihedrals;
            univ.impropers = impropers;
            //univ.nonbondeds   = nonbondeds  ;  // do not make this list in advance, because it depends on the atom positions
            univ.nonbonded14s = nonbonded14s;
            return(univ);
        }
示例#12
0
 public NInchiBond Add(NInchiBond bond)
 {
     Bonds.Add(bond);
     return(bond);
 }
示例#13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["currentUser"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    User currentUser = (User)Session["currentUser"];

                    TNFDAO          tnfDAO          = new TNFDAO();
                    UserDAO         userDAO         = new UserDAO();
                    NotificationDAO notificationDAO = new NotificationDAO();

                    int notificationID = Convert.ToInt32(Request.QueryString["n"]);

                    Notification currentNotification = notificationDAO.getNotificationByID(notificationID);

                    if (currentNotification == null || !currentNotification.getUserIDTo().Equals(currentUser.getUserID()))
                    {
                        Response.Redirect("errorPage.aspx");
                    }

                    TNF  currentTNF = tnfDAO.getIndividualTNFByID(currentNotification.getUserIDFrom(), currentNotification.getTNFID());
                    User applicant  = userDAO.getUserByID(currentNotification.getUserIDFrom());

                    Course   courseApplied   = tnfDAO.getCourseFromTNF(currentNotification.getTNFID());
                    Lesson   lessonApplied   = tnfDAO.getLessonFromTNF(currentNotification.getTNFID());
                    TNFData  tnfData         = tnfDAO.getIndividualTNFDataByID(currentNotification.getTNFID());
                    Workflow currentWorkflow = currentTNF.getWorkflow();
                    int      probationPeriod = currentWorkflow.getProbationPeriod();
                    TimeSpan ts = currentTNF.getApplicationDate().Subtract(applicant.getStartDate());

                    //show warning if overseas, probation, > 10000
                    if (courseApplied.getPrice() > 10000)
                    {
                        warningPanelPrice.Visible = true;
                        lblWarningPrice.Visible   = true;
                        lblWarningPrice.Text      = "This course is over $10,000";
                    }
                    if (courseApplied.getOverseas().ToLower().Equals("y"))
                    {
                        warningPanelOverseas.Visible = true;
                        lblWarningOverseas.Visible   = true;
                        lblWarningOverseas.Text      = "This course is an overseas course";
                    }
                    if (ts.TotalDays < probationPeriod)
                    {
                        warningPanelProbation.Visible = true;
                        lblWarningProbation.Visible   = true;
                        probationDate.Enabled         = true;
                        lblWarningProbation.Text      = "Applicant is under probation";
                    }

                    //setting user information
                    nameOfStaffOutput.Text    = applicant.getName();
                    employeeNumberOutput.Text = applicant.getUserID();
                    emailOutput.Text          = applicant.getEmail();
                    designationOutput.Text    = applicant.getJobTitle();
                    departmentOutput.Text     = applicant.getDepartment();

                    //setting course and lesson information
                    courseOutput.Text     = courseApplied.getCourseName();
                    startDate.Text        = lessonApplied.getStartDate().ToString("d MMM yyyy");
                    endDate.Text          = lessonApplied.getEndDate().ToString("d MMM yyyy");
                    startTime.Text        = lessonApplied.getStartTime().ToString();
                    endTime.Text          = lessonApplied.getEndTime().ToString();
                    venueOutput.Text      = lessonApplied.getVenue();
                    instructorOutput.Text = lessonApplied.getInstructor();

                    string internalOrExternal = courseApplied.getInternalOrExternal();
                    if (internalOrExternal.ToLower().Equals("internal"))
                    {
                        inhouse.Checked     = true;
                        external.Checked    = false;
                        lblExternal.Visible = false;
                        externalCourseProviderOutput.Visible = false;
                    }
                    else
                    {
                        inhouse.Checked     = false;
                        external.Checked    = true;
                        lblExternal.Visible = true;
                        externalCourseProviderOutput.Visible = true;
                        externalCourseProviderOutput.Text    = courseApplied.getCourseProvider();
                    }
                    courseFeeOutput.Text = "$" + courseApplied.getPrice();

                    //setting tnf data information
                    string prepareForNewJobRole = tnfData.getPrepareForNewJobRole();
                    if (prepareForNewJobRole.Equals("y"))
                    {
                        objectiveInput1.Checked  = true;
                        objectiveElaborate1.Text = tnfData.getPrepareForNewJobRoleText();
                        completeDateOutput1.Text = tnfData.getPrepareForNewJobRoleCompletionDate().Value.ToString("MM-dd-yyyy");
                    }
                    else
                    {
                        objectiveInput1.Checked  = false;
                        objectiveElaborate1.Text = "-";
                        completeDateOutput1.Text = "-";
                    }

                    string shareKnowledge = tnfData.getShareKnowledge();
                    if (shareKnowledge.Equals("y"))
                    {
                        objectiveInput2.Checked  = true;
                        objectiveElaborate2.Text = tnfData.getShareKnowledgeText();
                        completeDateOutput2.Text = tnfData.getShareKnowledgeCompletionDate().Value.ToString("MM-dd-yyyy");
                    }
                    else
                    {
                        objectiveInput2.Checked  = false;
                        objectiveElaborate2.Text = "-";
                        completeDateOutput2.Text = "-";
                    }

                    string otherObjectives = tnfData.getOtherObjectives();
                    if (otherObjectives.Equals("y"))
                    {
                        objectiveInput3.Checked    = true;
                        objectiveElaborate3.Text   = tnfData.getOtherObjectivesText();
                        completionDateOutput3.Text = tnfData.getOtherObjectivesCompletionDate().Value.ToString("MM-dd-yyyy");
                    }
                    else
                    {
                        objectiveInput3.Checked    = false;
                        objectiveElaborate3.Text   = "-";
                        completionDateOutput3.Text = "-";
                    }

                    //all HR will view HR approval section
                    if (currentUser.getJobCategory().Equals("hr"))
                    {
                        hrApprovalView.Visible = true;
                        BondDAO    bondDAO     = new BondDAO();
                        DeptDAO    deptDAO     = new DeptDAO();
                        Bonds      checkBond   = bondDAO.getBondByTNFIDandUserID(currentTNF.getTNFID(), applicant.getUserID());
                        Department currentDept = deptDAO.getDeptByName(applicant.getDepartment());
                        lbl_HR.Text = "Is HR";
                        rfv_trainingCost.Enabled    = true;
                        rfv_mspBondDuration.Enabled = true;

                        if (checkBond != null)
                        {
                            rbtnBond.Checked        = true;
                            rbtnMSP.Enabled         = false;
                            rbtnNA.Enabled          = false;
                            mspBondDuration.Text    = string.Empty;
                            mspBondDuration.Enabled = true;
                        }
                        else
                        {
                            rbtnBond.Checked = false;
                            rbtnBond.Enabled = false;
                        }

                        costcentre.Text = currentDept.getCostCentre().ToString();
                        double balance = currentDept.getActualBudget() - courseApplied.getPrice();
                        trainingBudgetBal.Text  = balance.ToString();
                        trainingBudgetDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
                    }
                    else
                    {
                        lbl_HR.Text = "Is not HR";
                        rfv_trainingCost.Enabled    = false;
                        rfv_mspBondDuration.Enabled = false;
                    }
                }
            }
        }
示例#14
0
        /// <summary>
        /// Rebuilds the molecule without trashing it totally
        /// </summary>
        /// <param name="seed">start Atom for refresh operation</param>
        private void Refresh(Atom seed = null)
        {
            //keep a list of the atoms to refer to later when rebuilding
            List <Atom> checklist = new List <Atom>();

            //set the parent to null but keep a list of all atoms
            foreach (Atom atom in Atoms)
            {
                atom.Parent = null;
                checklist.Add(atom);
            }

            //clear the associated collections
            Atoms.RemoveAll();
            AllAtoms.RemoveAll();
            foreach (Bond bond in Bonds)
            {
                bond.Parent = null;
            }
            Bonds.RemoveAll();
            AllBonds.RemoveAll();
            Rings.RemoveAll();

            //if we've been provided with a seed atom, use that
            //else use the first atom in the checklist

            if (seed == null)
            {
                seed = checklist[0];
            }
            //now traverse the tree as far as it will go

            DepthFirstTraversal(seed,
                                operation: atom =>
            {
                Atoms.Add(atom);

                foreach (Bond b in atom.Bonds.Where(b => b.Parent == null))
                {
                    Bonds.Add(b);
                }
                if (checklist.Contains(atom))
                {
                    checklist.Remove(atom);
                }
            },
                                isntProcessed: atom => atom.Parent == null);
            //only if the molecule has rings do we rebuild it
            RebuildRings();

            //now we check to see whether there are any more unconnected regions lurking around

            while (checklist.Count > 0)//means we haven't yet accounted for all the original atoms
            {
                seed = checklist[0];
                Molecule addnlMol = new Molecule();
                DepthFirstTraversal(seed,
                                    operation: atom =>
                {
                    addnlMol.Atoms.Add(atom);

                    foreach (Bond b in atom.Bonds.Where(b => b.Parent == null))
                    {
                        addnlMol.Bonds.Add(b);
                    }
                    if (checklist.Contains(atom))
                    {
                        checklist.Remove(atom);
                    }
                },
                                    isntProcessed: atom => atom.Parent == null);
                //only if the molecule has rings do we rebuild it
                addnlMol.RebuildRings();
                this.Parent.Molecules.Add(addnlMol);
            }
        }
示例#15
0
            public static Universe Build(Tinker.Xyz xyz, Tinker.Prm prm, Pdb pdb
                                         , double?tolCoordPdbXyz // 0.002 for default distance
                                                                 //    (0.001 * sqrt(3) = 0.0017321, which is the largest tolerance between pdb and xyz)
                                                                 // null  for not ordering by distance;
                                         )
            {
                Universe univ = new Universe();

                Dictionary <int, Prm.Atom>                            prm_id2atom      = prm.atoms.ToIdDictionary();
                Dictionary <int, Prm.Vdw>                             prm_cls2vdw      = prm.vdws.ToClassDictionary();
                Dictionary <int, Prm.Vdw14>                           prm_cls2vdw14    = prm.vdw14s.ToClassDictionary();
                Dictionary <Tuple <int, int>, Prm.Bond>               prm_cls2bond     = prm.bonds.ToClassDictionary();
                Dictionary <Tuple <int, int, int>, Prm.Angle>         prm_cls2angle    = prm.angles.ToClassDictionary();
                Dictionary <Tuple <int, int, int>, Prm.Ureybrad>      prm_cls2ureybrad = prm.ureybrads.ToClassDictionary();
                Dictionary <Tuple <int, int, int, int>, Prm.Improper> prm_cls2improper = prm.impropers.ToClassDictionary();
                Dictionary <Tuple <int, int, int, int>, Prm.Torsion>  prm_cls2torsion  = prm.torsions.ToClassDictionary();
                Dictionary <int, Prm.Charge>                          prm_id2charge    = prm.charges.ToIdDictionary();

                Prm.Biotype[] prm_biotypes = prm.biotypes;

                Xyz.Atom[] xyz_atoms = xyz.atoms;
                Pdb.Atom[] pdb_atoms = (pdb != null) ? pdb.atoms : null;
                Dictionary <int, Xyz.Atom> xyz_id2atom = xyz_atoms.ToIdDictionary();

                KDTree.KDTree <Tuple <int, Pdb.Atom> > coord2pdbatom = null;
                {
                    if (pdb_atoms != null)
                    {
                        coord2pdbatom = new KDTree.KDTree <Tuple <int, Pdb.Atom> >(3);
                        for (int ia = 0; ia < pdb_atoms.Length; ia++)
                        {
                            Pdb.Atom pdb_atom = pdb_atoms[ia];
                            Vector   coord    = pdb_atom.coord;
                            coord2pdbatom.insert(coord.ToArray(), new Tuple <int, Pdb.Atom>(ia, pdb_atom));
                        }
                    }
                }

                Atoms atoms = new Atoms(univ);

                /// Debug.Assert(pdb.atoms.Length == top_atoms.Count);
                for (int i = 0; i < xyz_atoms.Length; i++)
                {
                    Xyz.Atom xyz_atom = xyz_atoms[i];
                    Pdb.Atom pdb_atom = null; // = (pdb_atoms != null) ? (pdb_atoms[i]) : null;
                    if (coord2pdbatom != null)
                    {
                        Vector xyz_coord = xyz_atom.Coord;
                        Tuple <int, Pdb.Atom> ia_atom = coord2pdbatom.nearest(xyz_coord);
                        Vector pdb_coord = ia_atom.Item2.coord;
                        if (tolCoordPdbXyz == null)
                        {
                            pdb_atom = pdb_atoms[i];
                        }
                        else
                        {
                            if ((xyz_coord - pdb_coord).Dist < tolCoordPdbXyz)
                            {
                                pdb_atom = ia_atom.Item2;
                            }
                            else
                            {
                                //HDebug.Assert(false);
                                pdb_atom = null;
                            }
                        }
                    }
                    if (pdb_atom != null)
                    {
                        string pdb_atom_type = pdb_atom.element.Trim();
                        string xyz_atom_type = xyz_atom.AtomType.Trim();
                        if (HDebug.IsDebuggerAttached && pdb_atom_type.Length > 0)   // sometimes element is blank: " "
                        {
                            HDebug.AssertIf(pdb_atom_type[0] == xyz_atom_type[0]);
                        }
                        if (tolCoordPdbXyz != null)
                        {
                            HDebug.AssertTolerance(tolCoordPdbXyz.Value, xyz_atom.Coord - pdb_atom.coord);
                        }
                    }
                    //if(pdb_atom != null) Debug.Assert(xyz_atom.Id == pdb_atom.serial);

                    HDebug.Assert(i + 1 == xyz_atom.Id);
                    Prm.Atom   prm_atom   = prm_id2atom  [xyz_atom.AtomId];
                    Prm.Charge prm_charge = prm_id2charge[xyz_atom.AtomId];
                    Prm.Vdw    prm_vdw    = null;
                    Prm.Vdw14  prm_vdw14  = null;
                    if (prm_cls2vdw.ContainsKey(prm_atom.Class))
                    {
                        prm_vdw = prm_cls2vdw  [prm_atom.Class];
                    }
                    if (prm_cls2vdw14.ContainsKey(prm_atom.Class))
                    {
                        prm_vdw14 = prm_cls2vdw14[prm_atom.Class];
                    }

                    if (pdb_atom != null)
                    {
                        if (pdb_atom.element.Trim() != "")
                        {
                            if (pdb_atom.element.Trim() != prm_atom.AtomElem)
                            {
                                throw new Exception();
                            }
                        }
                    }

                    Atom uatom = new Atom(AtomId: xyz_atom.Id
                                          , AtomName: ((pdb_atom != null) ? (pdb_atom.name.Trim()) : ("?" + prm_atom.Type))     /// fix later
                                          , AtomType: prm_atom.Type
                                          , AtomElem: prm_atom.AtomElem
                                          , ResidueId: ((pdb_atom != null) ? (pdb_atom.resSeq) : (-1))                          /// fix later
                                          , ResidueName: ((pdb_atom != null) ? (pdb_atom.resName.Trim()) : ("?res"))            /// fix later
                                          , Charge: prm_charge.pch
                                          , Mass: prm_atom.Mass
                                          , epsilon: ((prm_vdw != null) ? prm_vdw.Epsilon    :          0)
                                          , Rmin2: ((prm_vdw != null) ? prm_vdw.Rmin2      :          0)
                                          , eps_14: ((prm_vdw14 != null) ? prm_vdw14.Eps_14   : double.NaN)
                                          , Rmin2_14: ((prm_vdw14 != null) ? prm_vdw14.Rmin2_14 : double.NaN)
                                          , sources: new object[] { xyz_atom, pdb_atom, prm_atom, prm_charge }
                                          );

                    uatom.Coord = xyz_atom.Coord;
                    atoms.Add(uatom);
                }


                // bonds
                Bonds bonds;

                {
                    Dictionary <Tuple <Atom, Atom>, Bond> lbonds = new Dictionary <Tuple <Atom, Atom>, Bond>();
                    for (int i = 0; i < xyz_atoms.Length; i++)
                    {
                        int  id0   = xyz_atoms[i].Id; HDebug.Assert(id0 == i + 1);
                        int  atm0  = xyz_atoms[i].AtomId;
                        int  cls0  = prm_id2atom[atm0].Class;
                        Atom atom0 = atoms[id0 - 1]; HDebug.Assert(atom0.AtomId == id0);

                        Tuple <int, int> cls;
                        foreach (int id1 in xyz_atoms[i].BondedIds)
                        {
                            int  atm1  = xyz_id2atom[id1].AtomId;
                            int  cls1  = prm_id2atom[atm1].Class;
                            Atom atom1 = atoms[id1 - 1]; HDebug.Assert(atom1.AtomId == id1);
                            HashSet <Prm.Bond> bondtypes = new HashSet <Prm.Bond>();
                            Atom[]             iatom     = null;
                            cls = new Tuple <int, int>(cls0, cls1); if (prm_cls2bond.ContainsKey(cls))
                            {
                                bondtypes.Add(prm_cls2bond[cls]); iatom = new Atom[] { atom0, atom1 };
                            }
                            cls = new Tuple <int, int>(cls1, cls0); if (prm_cls2bond.ContainsKey(cls))
                            {
                                bondtypes.Add(prm_cls2bond[cls]); iatom = new Atom[] { atom1, atom0 };
                            }
                            HDebug.Assert(bondtypes.Count == 1);
                            if (bondtypes.Count >= 1)
                            {
                                Prm.Bond bondtype = bondtypes.Last();
                                HDebug.Assert(bondtype != null);

                                // sort atom id, in order to avoid duplication of bonds such that (0,1) and (1,0)
                                if (iatom.First().ID > iatom.Last().ID)
                                {
                                    iatom = iatom.Reverse().ToArray();
                                }

                                var  key  = new Tuple <Atom, Atom>(iatom[0], iatom[1]);
                                Bond bond = new Bond(iatom[0], iatom[1], bondtype.Kb, bondtype.b0, bondtype);
                                if (lbonds.ContainsKey(key) == false)
                                {
                                    lbonds.Add(key, bond);
                                }
                                else
                                {
                                    HDebug.Assert(bond.Kb == lbonds[key].Kb);
                                    HDebug.Assert(bond.b0 == lbonds[key].b0);
                                }
                            }
                        }
                    }
                    bonds = new Bonds();
                    foreach (Bond bond in lbonds.Values)
                    {
                        HDebug.Assert(bond.atoms.Length == 2);
                        HDebug.Assert(bond.atoms[0].ID < bond.atoms[1].ID);
                        bonds.Add(bond);
                        Atom atom0 = bond.atoms[0];
                        Atom atom1 = bond.atoms[1];
                        atom0.Bonds.Add(bond); atom0.Inter123.Add(atom1); atom0.Inter12.Add(atom1);
                        atom1.Bonds.Add(bond); atom1.Inter123.Add(atom0); atom1.Inter12.Add(atom0);
                    }
                }

                HashSet <Atom>[] inter12 = new HashSet <Atom> [xyz_atoms.Length];
                HashSet <Tuple <Atom, Atom>     >[]   inter123  = new HashSet <Tuple <Atom, Atom>     > [xyz_atoms.Length];
                HashSet <Tuple <Atom, Atom, Atom> >[] inter1234 = new HashSet <Tuple <Atom, Atom, Atom> > [xyz_atoms.Length];
                {
                    HDebug.Assert(xyz_atoms.Length == atoms.Count);
                    foreach (Atom atom in atoms)
                    {
                        inter12  [atom.ID] = new HashSet <Atom>(atom.Inter12);
                        inter123 [atom.ID] = new HashSet <Tuple <Atom, Atom>      >();
                        inter1234[atom.ID] = new HashSet <Tuple <Atom, Atom, Atom> >();
                    }

                    // build inter123 and inter1234
                    for (int i = 0; i < xyz_atoms.Length; i++)
                    {
                        Atom atom0 = atoms[i];
                        HDebug.Assert(atom0.ID == i);
                        foreach (Atom atom1 in inter12[atom0.ID])
                        {
                            HDebug.Assert(atom0 != atom1);
                            foreach (Atom atom2 in inter12[atom1.ID])
                            {
                                HDebug.Assert(atom1 != atom2);
                                if (atom0 == atom2)
                                {
                                    continue;
                                }
                                inter123[atom0.ID].Add(new Tuple <Atom, Atom>(atom1, atom2));
                                foreach (Atom atom3 in inter12[atom2.ID])
                                {
                                    HDebug.Assert(atom2 != atom3);
                                    if (atom0 == atom2)
                                    {
                                        continue;
                                    }
                                    if (atom0 == atom3)
                                    {
                                        continue;
                                    }
                                    if (atom1 == atom3)
                                    {
                                        continue;
                                    }
                                    inter1234[atom0.ID].Add(new Tuple <Atom, Atom, Atom>(atom1, atom2, atom3));
                                }
                            }
                        }
                    }
                }

                // angles
                Angles angles;
                {
                    Dictionary <Tuple <Atom, Atom, Atom>, Angle> langles = new Dictionary <Tuple <Atom, Atom, Atom>, Angle>();
                    foreach (Atom atom0 in atoms)
                    {
                        int id0  = xyz_atoms[atom0.ID].Id; HDebug.Assert(id0 == atom0.ID + 1);
                        int atm0 = xyz_atoms[atom0.ID].AtomId;
                        int cls0 = prm_id2atom[atm0].Class;

                        foreach (var atom123 in inter123[atom0.ID])
                        {
                            Atom atom1 = atom123.Item1; int atm1 = xyz_atoms[atom1.ID].AtomId; int cls1 = prm_id2atom[atm1].Class;
                            Atom atom2 = atom123.Item2; int atm2 = xyz_atoms[atom2.ID].AtomId; int cls2 = prm_id2atom[atm2].Class;

                            Tuple <int, int, int> cls;
                            Atom[] iatom = null;
                            HashSet <Prm.Angle>    angs = new HashSet <Prm.Angle>();
                            HashSet <Prm.Ureybrad> urbs = new HashSet <Prm.Ureybrad>();
                            cls = new Tuple <int, int, int>(cls0, cls1, cls2); if (prm_cls2angle.ContainsKey(cls))
                            {
                                angs.Add(prm_cls2angle[cls]); iatom = new Atom[] { atom0, atom1, atom2 };
                            }
                            if (prm_cls2ureybrad.ContainsKey(cls))
                            {
                                urbs.Add(prm_cls2ureybrad[cls]);
                            }
                            cls = new Tuple <int, int, int>(cls2, cls1, cls0); if (prm_cls2angle.ContainsKey(cls))
                            {
                                angs.Add(prm_cls2angle[cls]); iatom = new Atom[] { atom2, atom1, atom0 };
                            }
                            if (prm_cls2ureybrad.ContainsKey(cls))
                            {
                                urbs.Add(prm_cls2ureybrad[cls]);
                            }
                            HDebug.Assert(angs.Count == 1);
                            HDebug.Assert(urbs.Count <= angs.Count);
                            if (angs.Count >= 1)
                            {
                                Prm.Angle ang = angs.Last();
                                HDebug.Assert(ang != null);
                                Prm.Ureybrad urb = null;
                                if (urbs.Count >= 1)
                                {
                                    urb = urbs.Last();
                                }

                                // sort atom id, in order to avoid duplication of bonds such that (0,1) and (1,0)
                                if (iatom.First().ID > iatom.Last().ID)
                                {
                                    iatom = iatom.Reverse().ToArray();
                                }

                                var   key   = new Tuple <Atom, Atom, Atom>(iatom[0], iatom[1], iatom[2]);
                                Angle angle = new Angle(iatom[0], iatom[1], iatom[2]
                                                        , Ktheta: ang.Ktheta
                                                        , Theta0: ang.Theta0
                                                        , Kub: ((urb != null) ? urb.Kub : 0)
                                                        , S0: ((urb != null) ? urb.S0  : 0)
                                                        , sources: new object[] { ang, urb }
                                                        );
                                if (langles.ContainsKey(key) == false)
                                {
                                    langles.Add(key, angle);
                                }
                                else
                                {
                                    HDebug.Assert(langles[key].Ktheta == angle.Ktheta
                                                  , langles[key].Theta0 == angle.Theta0
                                                  , langles[key].Kub == angle.Kub
                                                  , langles[key].S0 == angle.S0
                                                  );
                                }
                            }
                        }
                    }
                    angles = new Angles();
                    foreach (Angle angle in langles.Values)
                    {
                        HDebug.Assert(angle.atoms.Length == 3);
                        HDebug.Assert(angle.atoms[0].ID < angle.atoms[2].ID);
                        angles.Add(angle);
                        Atom atom0 = angle.atoms[0];
                        Atom atom1 = angle.atoms[1];
                        Atom atom2 = angle.atoms[2];
                        atom0.Angles.Add(angle); atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2);
                        atom1.Angles.Add(angle); atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom0);
                        atom2.Angles.Add(angle); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                    }
                }

                // dihedrals
                Dihedrals dihedrals;
                {
                    Dictionary <Tuple <Atom, Atom, Atom, Atom>, List <Dihedral> > ldihedrals = new Dictionary <Tuple <Atom, Atom, Atom, Atom>, List <Dihedral> >();
                    foreach (Atom atom0 in atoms)
                    {
                        int id0  = xyz_atoms[atom0.ID].Id; HDebug.Assert(id0 == atom0.ID + 1);
                        int atm0 = xyz_atoms[atom0.ID].AtomId;
                        int cls0 = prm_id2atom[atm0].Class;

                        Tuple <int, int, int, int> cls;
                        foreach (var atom1234 in inter1234[atom0.ID])
                        {
                            Atom atom1 = atom1234.Item1; int atm1 = xyz_atoms[atom1.ID].AtomId; int cls1 = prm_id2atom[atm1].Class;
                            Atom atom2 = atom1234.Item2; int atm2 = xyz_atoms[atom2.ID].AtomId; int cls2 = prm_id2atom[atm2].Class;
                            Atom atom3 = atom1234.Item3; int atm3 = xyz_atoms[atom3.ID].AtomId; int cls3 = prm_id2atom[atm3].Class;

                            HashSet <Prm.Torsion> tors = new HashSet <Prm.Torsion>();
                            Atom[] iatom = null;
                            cls = new Tuple <int, int, int, int>(cls0, cls1, cls2, cls3); if (prm_cls2torsion.ContainsKey(cls))
                            {
                                tors.Add(prm_cls2torsion[cls]); iatom = new Atom[] { atom0, atom1, atom2, atom3 };
                            }
                            cls = new Tuple <int, int, int, int>(cls3, cls2, cls1, cls0); if (prm_cls2torsion.ContainsKey(cls))
                            {
                                tors.Add(prm_cls2torsion[cls]); iatom = new Atom[] { atom3, atom2, atom1, atom0 };
                            }
                            HDebug.Assert(tors.Count == 1);
                            if (tors.Count >= 1)
                            {
                                // sort atom id, in order to avoid duplication of bonds such that (0,1) and (1,0)
                                if (iatom.First().ID > iatom.Last().ID)
                                {
                                    iatom = iatom.Reverse().ToArray();
                                }

                                var key = new Tuple <Atom, Atom, Atom, Atom>(iatom[0], iatom[1], iatom[2], iatom[3]);
                                if (ldihedrals.ContainsKey(key) == false)
                                {
                                    ldihedrals.Add(key, new List <Dihedral>());

                                    Prm.Torsion tor = tors.Last();
                                    foreach (var tordat in tor.GetListData())
                                    {
                                        Dihedral dihedral = new Dihedral(iatom[0], iatom[1], iatom[2], iatom[3]
                                                                         , Kchi: tordat.Kchi
                                                                         , n: tordat.n
                                                                         , delta: tordat.delta
                                                                         , sources: new object[] { tor }
                                                                         );
                                        ldihedrals[key].Add(dihedral);
                                        HDebug.Assert(dihedral.n != 0);
                                    }
                                }
                                else
                                {
                                    // do not check its contents because ...
                                }
                            }
                        }
                    }
                    dihedrals = new Dihedrals();
                    foreach (var ldihedral in ldihedrals.Values)
                    {
                        foreach (Dihedral dihedral in ldihedral)
                        {
                            HDebug.Assert(dihedral.atoms.Length == 4);
                            HDebug.Assert(dihedral.atoms[0].ID < dihedral.atoms[3].ID);
                            dihedrals.Add(dihedral);
                            dihedral.atoms[0].Dihedrals.Add(dihedral);
                            dihedral.atoms[1].Dihedrals.Add(dihedral);
                            dihedral.atoms[2].Dihedrals.Add(dihedral);
                            dihedral.atoms[3].Dihedrals.Add(dihedral);
                        }
                    }
                }

                // impropers
                Impropers impropers = new Impropers();

                {
                    Dictionary <Tuple <Atom, Atom, Atom, Atom>, Improper> limpropers = new Dictionary <Tuple <Atom, Atom, Atom, Atom>, Improper>();
                    foreach (Atom atom0 in atoms)
                    {
                        ///       ####################################
                        ///       ##                                ##
                        ///       ##  Improper Dihedral Parameters  ##
                        ///       ##                                ##
                        ///       ####################################
                        ///
                        ///    ##################################################################
                        ///    ##                                                              ##
                        ///    ##  Following CHARMM style, the improper for a trigonal atom    ##
                        ///    ##  D bonded to atoms A, B and C could be input as improper     ##
                        ///    ##  dihedral angle D-A-B-C. The actual angle computed by the    ##
                        ///    ##  program is then literally the dihedral D-A-B-C, which will  ##
                        ///    ##  always have as its ideal value zero degrees. In general     ##
                        ///    ##  D-A-B-C is different from D-B-A-C; the order of the three   ##
                        ///    ##  peripheral atoms matters. In the original CHARMM parameter  ##
                        ///    ##  files, the trigonal atom is often listed last; ie, as       ##
                        ///    ##  C-B-A-D instead of D-A-B-C.                                 ##
                        ///    ##                                                              ##
                        ///    ##  Some of the improper angles are "double counted" in the     ##
                        ///    ##  CHARMM protein parameter set. Since TINKER uses only one    ##
                        ///    ##  improper parameter per site, we have doubled these force    ##
                        ///    ##  constants in the TINKER version of the CHARMM parameters.   ##
                        ///    ##  Symmetric parameters, which are the origin of the "double   ##
                        ///    ##  counted" CHARMM values, are handled in the TINKER package   ##
                        ///    ##  by assigning all symmetric states and using the TINKER      ##
                        ///    ##  force constant divided by the symmetry number.              ##
                        ///    ##                                                              ##
                        ///    ##  ...                                                         ##
                        ///    ##################################################################

                        int id0  = xyz_atoms[atom0.ID].Id; HDebug.Assert(id0 == atom0.ID + 1);
                        int atm0 = xyz_atoms[atom0.ID].AtomId;
                        int cls0 = prm_id2atom[atm0].Class;

                        bool bAtom0InImpropers = false;
                        foreach (var cls in prm_cls2improper.Keys)
                        {
                            if (cls.Item1 == cls0)
                            {
                                bAtom0InImpropers = true;
                            }
                        }
                        if (bAtom0InImpropers == false)
                        {
                            continue;
                        }

                        Atom[] bondeds0 = inter12[atom0.ID].ToArray();
                        if (bondeds0.Length < 3)
                        {
                            continue;
                        }
                        for (int i = 0; i < bondeds0.Length - 2; i++)
                        {
                            Atom atom1 = bondeds0[i];
                            int  atm1  = xyz_atoms[atom1.ID].AtomId;
                            int  cls1  = prm_id2atom[atm1].Class;
                            for (int j = i + 1; j < bondeds0.Length - 1; j++)
                            {
                                Atom atom2 = bondeds0[j];
                                int  atm2  = xyz_atoms[atom2.ID].AtomId;
                                int  cls2  = prm_id2atom[atm2].Class;
                                for (int k = j + 1; k < bondeds0.Length; k++)
                                {
                                    Atom atom3 = bondeds0[k];
                                    int  atm3  = xyz_atoms[atom3.ID].AtomId;
                                    int  cls3  = prm_id2atom[atm3].Class;

                                    Tuple <int, int, int, int> cls;
                                    HashSet <Prm.Improper>     imps = new HashSet <Prm.Improper>();
                                    Atom[] iatom = null;
                                    cls = new Tuple <int, int, int, int>(cls0, cls1, cls2, cls3); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom0, atom1, atom2, atom3 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls3, cls2, cls1, cls0); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom3, atom2, atom1, atom0 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls0, cls1, cls3, cls2); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom0, atom1, atom3, atom2 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls2, cls3, cls1, cls0); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom2, atom3, atom1, atom0 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls0, cls2, cls1, cls3); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom0, atom2, atom1, atom3 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls3, cls1, cls2, cls0); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom3, atom1, atom2, atom0 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls0, cls2, cls3, cls1); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom0, atom2, atom3, atom1 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls1, cls3, cls2, cls0); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom1, atom3, atom2, atom0 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls0, cls3, cls1, cls2); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom0, atom3, atom1, atom2 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls2, cls1, cls3, cls0); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom2, atom1, atom3, atom0 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls0, cls3, cls2, cls1); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom0, atom3, atom2, atom1 };
                                    }
                                    cls = new Tuple <int, int, int, int>(cls1, cls2, cls3, cls0); if (prm_cls2improper.ContainsKey(cls))
                                    {
                                        imps.Add(prm_cls2improper[cls]); iatom = new Atom[] { atom1, atom2, atom3, atom0 };
                                    }
                                    HDebug.Assert(imps.Count <= 1); // for example, H-C-HHH has C-HHH connectivity but it is not improper...
                                                                    // so imps.count <= 1
                                    if (imps.Count >= 1)
                                    {
                                        Prm.Improper imp = imps.Last(); // because iatoms contains the last case only.

                                        ///////////////////////////////////////////////////////////////////////////////////////
                                        // This bug was raised by Jae-Kyun Song at 2016-04-01                                //
                                        // In 1AAC, (1501,C)-(1503,NC2)-(1502,NC2)-(1500,NC2) is reordered                   //
                                        //       as (1500,NC2)-(1502,NC2)-(1503,NC2)-(1501,C)                                //
                                        // This bug was originally copied from dihedral code that is added to prevent adding //
                                        // duplicated interactions such as 1-2-3-4 and 4-3-2-1.                              //
                                        ///////////////////////////////////////////////////////////////////////////////////////
                                        /// old code
                                        //  // sort atom id, in order to avoid duplication of bonds such that (0,1) and (1,0)
                                        //  if(iatom.First().ID > iatom.Last().ID)
                                        //      iatom = iatom.Reverse().ToArray();
                                        //  var key = new Tuple<Atom, Atom, Atom, Atom>(iatom[0], iatom[1], iatom[2], iatom[3]);
                                        ///////////////////////////////////////////////////////////////////////////////////////
                                        /// new code
                                        Tuple <Atom, Atom, Atom, Atom> key;
                                        {
                                            Atom   key0   = iatom[0];
                                            Atom[] key123 = (new Atom[] { iatom[1], iatom[2], iatom[3] }).SortByIDs();
                                            key = new Tuple <Atom, Atom, Atom, Atom>(key0, key123[0], key123[1], key123[2]);
                                        }
                                        ///////////////////////////////////////////////////////////////////////////////////////

                                        Improper improper = new Improper(iatom[0], iatom[1], iatom[2], iatom[3]
                                                                         , Kpsi: imp.Kpsi
                                                                         , psi0: imp.psi0
                                                                         , sources: new object[] { imp }
                                                                         );

                                        if (limpropers.ContainsKey(key) == false)
                                        {
                                            limpropers.Add(key, improper);
                                        }
                                        else
                                        {
                                            HDebug.Assert(limpropers[key].Kpsi == improper.Kpsi
                                                          , limpropers[key].psi0 == improper.psi0
                                                          );
                                        }
                                    }
                                }
                            }
                        }
                    }
                    foreach (var improper in limpropers.Values)
                    {
                        HDebug.Assert(improper.atoms.Length == 4);
                        //HDebug.Assert(improper.atoms[0].ID < improper.atoms[3].ID);
                        impropers.Add(improper);
                        improper.atoms[0].Impropers.Add(improper);
                        improper.atoms[1].Impropers.Add(improper);
                        improper.atoms[2].Impropers.Add(improper);
                        improper.atoms[3].Impropers.Add(improper);
                    }
                }

                // 1-4 interactions
                for (int i = 0; i < atoms.Count; i++)
                {
                    HashSet <Atom> Inter14 = new HashSet <Atom>();
                    BuildInter1toN(atoms[i], 4, Inter14); // find all atoms for 1-4 interaction
                    Inter14.Remove(atoms[i]);             // remove self
                    foreach (Atom atom in atoms[i].Inter123)
                    {
                        Inter14.Remove(atom);             // remove all 1-2, 1-3 interactions
                    }
                    atoms[i].Inter14 = Inter14;
                }
                Nonbonded14s nonbonded14s = new Nonbonded14s();

                nonbonded14s.Build(atoms);

                //// nonbondeds
                //// do not make this list in advance, because it depends on the atom positions
                //Nonbondeds nonbondeds = new Nonbondeds();
                //nonbondeds.Build(atoms);


                //Universe univ = new Universe();
                univ.pdb = pdb;
                univ.refs.Add("xyz", xyz);
                univ.refs.Add("prm", prm);
                univ.refs.Add("pdb", pdb);
                univ.atoms     = atoms;
                univ.bonds     = bonds;
                univ.angles    = angles;
                univ.dihedrals = dihedrals;
                univ.impropers = impropers;
                //univ.nonbondeds   = nonbondeds  ;  // do not make this list in advance, because it depends on the atom positions
                univ.nonbonded14s = nonbonded14s;

                HDebug.Assert(univ.Verify());
                if (HDebug.False)
                {
                    List <Tuple <double, string, Bond> > lbnds = new List <Tuple <double, string, Bond> >();
                    foreach (Bond bnd in bonds)
                    {
                        lbnds.Add(new Tuple <double, string, Bond>(bnd.Kb
                                                                   , bnd.atoms[0].AtomType + "-" + bnd.atoms[1].AtomType
                                                                   , bnd));
                    }
                    lbnds = lbnds.HSelectByIndex(lbnds.HListItem1().HIdxSorted().Reverse().ToArray()).ToList();
                    double avgKb = lbnds.HListItem1().Average();

                    List <Tuple <double, string, Angle> > langs   = new List <Tuple <double, string, Angle> >();
                    List <Tuple <double, string, Angle> > langubs = new List <Tuple <double, string, Angle> >();
                    foreach (Angle ang in angles)
                    {
                        langs.Add(new Tuple <double, string, Angle>(ang.Ktheta
                                                                    , ang.atoms[0].AtomType + "-" + ang.atoms[1].AtomType + "-" + ang.atoms[2].AtomType
                                                                    , ang));
                        if (ang.Kub != 0)
                        {
                            langubs.Add(new Tuple <double, string, Angle>(ang.Kub
                                                                          , ang.atoms[0].AtomType + "-" + ang.atoms[1].AtomType + "-" + ang.atoms[2].AtomType
                                                                          , ang));
                        }
                    }
                    langs   = langs.HSelectByIndex(langs.HListItem1().HIdxSorted().Reverse().ToArray()).ToList();
                    langubs = langubs.HSelectByIndex(langubs.HListItem1().HIdxSorted().Reverse().ToArray()).ToList();
                    double avgKtheta = langs.HListItem1().Average();
                    double avgKub    = langubs.HListItem1().Average();

                    List <Tuple <double, string, Improper> > limps = new List <Tuple <double, string, Improper> >();
                    foreach (Improper imp in impropers)
                    {
                        limps.Add(new Tuple <double, string, Improper>(imp.Kpsi
                                                                       , imp.atoms[0].AtomType + "-" + imp.atoms[1].AtomType + "-" + imp.atoms[2].AtomType + "-" + imp.atoms[3].AtomType
                                                                       , imp));
                    }
                    limps = limps.HSelectByIndex(limps.HListItem1().HIdxSorted().Reverse().ToArray()).ToList();
                    double avgKpsi = limps.HListItem1().Average();

                    List <Tuple <double, string, Dihedral> > ldihs = new List <Tuple <double, string, Dihedral> >();
                    foreach (Dihedral dih in dihedrals)
                    {
                        ldihs.Add(new Tuple <double, string, Dihedral>(dih.Kchi
                                                                       , dih.atoms[0].AtomType + "-" + dih.atoms[1].AtomType + "-" + dih.atoms[2].AtomType + "-" + dih.atoms[3].AtomType
                                                                       , dih));
                    }
                    ldihs = ldihs.HSelectByIndex(ldihs.HListItem1().HIdxSorted().Reverse().ToArray()).ToList();
                    double avgKchi = ldihs.HListItem1().Average();
                }
                return(univ);
            }
示例#16
0
        protected void cfmApproveBtn_Click(object sender, EventArgs e)
        {
            TNFDAO          tnfDAO          = new TNFDAO();
            UserDAO         userDAO         = new UserDAO();
            BondDAO         bondDAO         = new BondDAO();
            NotificationDAO notificationDAO = new NotificationDAO();

            int notificationID = Convert.ToInt32(Request.QueryString["n"]);

            Notification currentNotification = notificationDAO.getNotificationByID(notificationID);
            TNF          currentTNF          = tnfDAO.getIndividualTNFByID(currentNotification.getUserIDFrom(), currentNotification.getTNFID());
            User         applicant           = userDAO.getUserByID(currentNotification.getUserIDFrom());
            User         approver            = userDAO.getUserByID(currentNotification.getUserIDTo());
            Bonds        checkBond           = bondDAO.getBondByTNFIDandUserID(currentTNF.getTNFID(), applicant.getUserID());
            User         currentUser         = (User)Session["currentUser"];

            if (currentUser.getJobCategory().Equals("hr"))
            {
                //to save HR form
                string   probationText          = "n";
                string   isFunding              = "n";
                string   isMSP                  = "n";
                string   duration               = "";
                string   sourceOfFunding        = txtSourceOfFunding.Text;
                DateTime?fundingApplicationDate = null;
                Workflow currentWorkflow        = currentTNF.getWorkflow();
                int      probationPeriod        = currentWorkflow.getProbationPeriod();
                TimeSpan ts = currentTNF.getApplicationDate().Subtract(applicant.getStartDate());

                if (ts.TotalDays < probationPeriod)
                {
                    probationText = "y";
                }
                if (rbnlFunding.SelectedValue.Equals("y"))
                {
                    isFunding = "y";
                }
                if (!txtFundingDate.Text.Equals(""))
                {
                    fundingApplicationDate = DateTime.ParseExact(txtFundingDate.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                }
                if (rbtnMSP.Checked)
                {
                    isMSP    = "y";
                    duration = mspBondDuration.Text;
                    tnfDAO.updateTNFDataHRFields(currentTNF.getTNFID(), probationText, Convert.ToDouble(trainingCost.Text), isFunding, sourceOfFunding, fundingApplicationDate, isMSP, duration);
                }
                else
                {
                    tnfDAO.updateTNFDataHRFields(currentTNF.getTNFID(), probationText, Convert.ToDouble(trainingCost.Text), isFunding, sourceOfFunding, fundingApplicationDate, "n", null);
                }

                if (checkBond != null)
                {
                    //update Bond end date to correspond to number of months entered
                    DateTime endDate = checkBond.getStartDate();
                    endDate = endDate.AddMonths(Convert.ToInt32(mspBondDuration.Text));
                    bondDAO.updateBondEndDate(checkBond.getBondID(), endDate);
                }
            }
            Workflow_Approve.makeApproval(currentTNF, approver, currentNotification, remarksInput.Text);
            Response.Redirect("approvalConfirmation.aspx");
        }
示例#17
0
 public void Add(Bonds bonds) => Rows.Add(createRow(bonds));
示例#18
0
 public void Replace(Bonds bonds, int i) => ReplaceBase(Rows, createRow(bonds), i);
示例#19
0
            public static Universe Build(Namd.Psf psf, Namd.Prm prm, Pdb pdb, bool?ignore_neg_occupancy, ITextLogger logger)
            {
                Universe univ = new Universe();

                // atoms
                Atoms atoms = new Atoms(univ);
                Dictionary <int, Atom> id_atom = new Dictionary <int, Atom>();

                Pdb.Atom[] pdb_atoms = pdb.atoms;
                HDebug.Assert(psf.atoms.Length == pdb_atoms.Length);
                for (int i = 0; i < psf.atoms.Length; i++)
                {
                    HDebug.Assert(pdb_atoms[i].try_serial == null || psf.atoms[i].AtomId == pdb_atoms[i].serial); // when num atoms in pdb is too large (>99999), it is marked as *****
                    string type0 = psf.atoms[i].AtomType;
                    Atom   atom  = new Atom(psf.atoms[i], prm.FindNonbonded(type0, logger), pdb_atoms[i]);
                    atom.Coord = pdb_atoms[i].coord;
                    {
                        if (ignore_neg_occupancy == null)
                        {
                            if (pdb_atoms[i].occupancy < 0)
                            {
                                throw new HException("unhandled negative occupancy during building universe");
                            }
                        }
                        else
                        {
                            if (ignore_neg_occupancy.Value && pdb_atoms[i].occupancy < 0)
                            {
                                continue;
                            }
                        }
                    }
                    atoms.Add(atom);
                    id_atom.Add(psf.atoms[i].AtomId, atom);
                }

                // bonds
                Bonds bonds = new Bonds();

                for (int i = 0; i < psf.bonds.GetLength(0); i++)
                {
                    int id0 = psf.bonds[i, 0]; if (id_atom.ContainsKey(id0) == false)
                    {
                        continue;
                    }
                    Atom atom0 = id_atom[id0]; string type0 = atom0.AtomType;
                    int  id1 = psf.bonds[i, 1]; if (id_atom.ContainsKey(id1) == false)
                    {
                        continue;
                    }
                    Atom atom1 = id_atom[id1]; string type1 = atom1.AtomType;
                    Bond bond = new Bond(atom0, atom1, prm.FindBond(type0, type1, logger));
                    bonds.Add(bond);
                    atom0.Bonds.Add(bond); atom0.Inter123.Add(atom1); atom0.Inter12.Add(atom1);
                    atom1.Bonds.Add(bond); atom1.Inter123.Add(atom0); atom1.Inter12.Add(atom0);
                }

                // angles
                Angles angles = new Angles();

                for (int i = 0; i < psf.angles.GetLength(0); i++)
                {
                    int id0 = psf.angles[i, 0]; if (id_atom.ContainsKey(id0) == false)
                    {
                        continue;
                    }
                    Atom atom0 = id_atom[id0]; string type0 = atom0.AtomType;
                    int  id1 = psf.angles[i, 1]; if (id_atom.ContainsKey(id1) == false)
                    {
                        continue;
                    }
                    Atom atom1 = id_atom[id1]; string type1 = atom1.AtomType;
                    int  id2 = psf.angles[i, 2]; if (id_atom.ContainsKey(id2) == false)
                    {
                        continue;
                    }
                    Atom atom2 = id_atom[id2]; string type2 = atom2.AtomType;
                    var  prm_angle = prm.FindAngle(type0, type1, type2, logger);
                    if (prm_angle == null)
                    {
                        HDebug.Assert(false);
                        logger.Log(string.Format
                                       ("try to add non-existing angle (({0}, prm {1})-({2}, prm {3})-({4}, prm {5})) in prm"
                                       , atom0, type0, atom1, type1, atom2, type2
                                       ));
                        continue;
                    }
                    Angle angle = new Angle(atom0, atom1, atom2, prm_angle);
                    angles.Add(angle);
                    atom0.Angles.Add(angle); atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2);
                    atom1.Angles.Add(angle); atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom0);
                    atom2.Angles.Add(angle); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                }

                // dihedrals
                Dihedrals dihedrals = new Dihedrals();

                for (int i = 0; i < psf.dihedrals.GetLength(0); i++)
                {
                    int id0 = psf.dihedrals[i, 0]; if (id_atom.ContainsKey(id0) == false)
                    {
                        continue;
                    }
                    Atom atom0 = id_atom[id0]; string type0 = atom0.AtomType;
                    int  id1 = psf.dihedrals[i, 1]; if (id_atom.ContainsKey(id1) == false)
                    {
                        continue;
                    }
                    Atom atom1 = id_atom[id1]; string type1 = atom1.AtomType;
                    int  id2 = psf.dihedrals[i, 2]; if (id_atom.ContainsKey(id2) == false)
                    {
                        continue;
                    }
                    Atom atom2 = id_atom[id2]; string type2 = atom2.AtomType;
                    int  id3 = psf.dihedrals[i, 3]; if (id_atom.ContainsKey(id3) == false)
                    {
                        continue;
                    }
                    Atom atom3 = id_atom[id3]; string type3 = atom3.AtomType;
                    var  prm_dihedrals = prm.FindDihedral(type0, type1, type2, type3, logger);
                    if (prm_dihedrals.Length == 0)
                    {
                        HDebug.Assert(false);
                        logger.Log(string.Format
                                       ("try to add non-existing dihedral (({0}, prm {1})-({2}, prm {3})-({4}, prm {5})-({6}, prm {7})) in prm"
                                       , atom0, type0, atom1, type1, atom2, type2, atom3, type3
                                       ));
                        continue;
                    }
                    foreach (var prm_dihedral in prm_dihedrals)
                    {
                        Dihedral dihedral;
                        if (atom0.ID < atom3.ID)
                        {
                            dihedral = new Dihedral(atom0, atom1, atom2, atom3, prm_dihedral);
                        }
                        else
                        {
                            dihedral = new Dihedral(atom3, atom2, atom1, atom0, prm_dihedral);
                        }
                        dihedrals.Add(dihedral);
                        atom0.Dihedrals.Add(dihedral); //atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom0.Inter123.Add(atom3);
                        atom1.Dihedrals.Add(dihedral); //atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom3); atom1.Inter123.Add(atom0);
                        atom2.Dihedrals.Add(dihedral); //atom2.Inter123.Add(atom3); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                        atom3.Dihedrals.Add(dihedral); //atom3.Inter123.Add(atom0); atom3.Inter123.Add(atom1); atom3.Inter123.Add(atom2);
                    }
                }

                // impropers
                Impropers impropers = new Impropers();

                for (int i = 0; i < psf.impropers.GetLength(0); i++)
                {
                    int id0 = psf.impropers[i, 0]; if (id_atom.ContainsKey(id0) == false)
                    {
                        continue;
                    }
                    Atom atom0 = id_atom[id0]; string type0 = atom0.AtomType;
                    int  id1 = psf.impropers[i, 1]; if (id_atom.ContainsKey(id1) == false)
                    {
                        continue;
                    }
                    Atom atom1 = id_atom[id1]; string type1 = atom1.AtomType;
                    int  id2 = psf.impropers[i, 2]; if (id_atom.ContainsKey(id2) == false)
                    {
                        continue;
                    }
                    Atom atom2 = id_atom[id2]; string type2 = atom2.AtomType;
                    int  id3 = psf.impropers[i, 3]; if (id_atom.ContainsKey(id3) == false)
                    {
                        continue;
                    }
                    Atom     atom3 = id_atom[id3]; string type3 = atom3.AtomType;
                    Improper improper = new Improper(atom0, atom1, atom2, atom3, prm.FindImproper(type0, type1, type2, type3, logger));
                    impropers.Add(improper);
                    atom0.Impropers.Add(improper); //atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom0.Inter123.Add(atom3);
                    atom1.Impropers.Add(improper); //atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom3); atom1.Inter123.Add(atom0);
                    atom2.Impropers.Add(improper); //atom2.Inter123.Add(atom3); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                    atom3.Impropers.Add(improper); //atom3.Inter123.Add(atom0); atom3.Inter123.Add(atom1); atom3.Inter123.Add(atom2);
                }

                // 1-4 interactions
                for (int i = 0; i < atoms.Count; i++)
                {
                    HashSet <Atom> Inter14 = new HashSet <Atom>();
                    BuildInter1toN(atoms[i], 4, Inter14); // find all atoms for 1-4 interaction
                    Inter14.Remove(atoms[i]);             // remove self
                    foreach (Atom atom in atoms[i].Inter123)
                    {
                        Inter14.Remove(atom);             // remove all 1-2, 1-3 interactions
                    }
                    atoms[i].Inter14 = Inter14;
                }
                Nonbonded14s nonbonded14s = new Nonbonded14s();

                nonbonded14s.Build(atoms);

                //// nonbondeds
                //// do not make this list in advance, because it depends on the atom positions
                //Nonbondeds nonbondeds = new Nonbondeds();
                //nonbondeds.Build(atoms);


                //Universe univ = new Universe();
                univ.pdb = pdb;
                univ.refs.Add("psf", psf);
                univ.refs.Add("prm", prm);
                univ.atoms     = atoms;
                univ.bonds     = bonds;
                univ.angles    = angles;
                univ.dihedrals = dihedrals;
                univ.impropers = impropers;
                //univ.nonbondeds   = nonbondeds  ;  // do not make this list in advance, because it depends on the atom positions
                univ.nonbonded14s = nonbonded14s;

                HDebug.Assert(univ.Verify());
                return(univ);
            }
示例#20
0
            public static Universe Build(Pdb pdb, Gromacs.Top top, ITextLogger logger)
            {
                Universe univ = new Universe();

                // atoms
                List <Top.Atom>          top_atoms         = top.elements.SelectSourceExtTop().ListAtom().SelectMatchToPdb(pdb.atoms);
                List <Top.Bond>          top_bonds         = top.elements.SelectSourceExtTop().ListType <Top.Bond>();
                List <Top.Pair>          top_pairs         = top.elements.SelectSourceExtTop().ListType <Top.Pair>(); ///Debug.ToDo("handle pairtype <= nbnd 1-4");
                List <Top.Angle>         top_angles        = top.elements.SelectSourceExtTop().ListType <Top.Angle>();
                List <Top.Dihedral>      top_dihedral      = top.elements.SelectSourceExtTop().ListType <Top.Dihedral>();
                List <Top.Atomtypes>     top_atomtypes     = top.elements.ListAtomtypes();
                List <Top.Bondtypes>     top_bondtypes     = top.elements.ListType <Top.Bondtypes>();
                List <Top.Angletypes>    top_angletypes    = top.elements.ListType <Top.Angletypes>();
                List <Top.Dihedraltypes> top_dihedraltypes = top.elements.ListType <Top.Dihedraltypes>();
                List <Top.Pairtypes>     top_pairtypes     = top.elements.ListType <Top.Pairtypes>();   ///Debug.ToDo("handle pairtype <= nbnd 1-4");

                {
                    ///Debug.ToDo("handle here");
                    List <Top.LineElement> elems = new List <Top.LineElement>(top.elements);
                    foreach (var elem in top_atoms)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_bonds)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_pairs)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_angles)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_dihedral)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_atomtypes)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_bondtypes)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_angletypes)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_dihedraltypes)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    foreach (var elem in top_pairtypes)
                    {
                        HDebug.Verify(elems.Remove(elem));
                    }
                    List <Top.LineElement> srcitp = new List <Top.LineElement>();
                    List <Top.LineElement> srctop = new List <Top.LineElement>();
                    for (int i = 0; i < elems.Count; i++)
                    {
                        if ((elems[i].source as string).EndsWith(".itp"))
                        {
                            srcitp.Add(elems[i]); elems[i] = null; continue;
                        }
                        if ((elems[i].source as string).EndsWith(".top"))
                        {
                            srctop.Add(elems[i]); elems[i] = null; continue;
                        }
                    }
                    elems = elems.HRemoveAllNull().ToList();
                    HDebug.Assert(elems.Count == 0);
                }

                Atoms atoms = new Atoms(univ);

                HDebug.Assert(pdb.atoms.Length == top_atoms.Count);
                for (int i = 0; i < top_atoms.Count; i++)
                {
                    //Debug.Assert(psf.atoms[i].AtomId == pdb.atoms[i].serial);
                    //string type0 = psf.atoms[i].AtomType;
                    //Atom atom = new Atom(psf.atoms[i], prm.FindNonbonded(type0, logger), pdb.atoms[i]);
                    //atom.Coord = pdb.atoms[i].coord;
                    //atoms.Add(atom);
                    Gromacs.Top.Atom atom = top_atoms[i];
                    HDebug.Assert(i + 1 == atom.cgnr);
                    HDebug.Assert(atom.cgnr == pdb.atoms[i].serial);
                    //Gromacs.Top.Atomtypes atomtype = top_atomtypes[atom.type];
                    List <Gromacs.Top.Atomtypes> atomtypes = FindTypes(top_atomtypes, atom.type);
                    HDebug.Assert(atomtypes.Count == 1);
                    Gromacs.Top.Atomtypes atomtype = atomtypes.Last();
                    //Debug.Assert(atom.charge == atomtype.charge);
                    //Debug.Assert(atom.mass   == atomtype.mass  );
                    Atom uatom = new Atom(atom.cgnr, atom.atom, atom.type, pdb.atoms[i].element.Trim()
                                          , atom.resnr, atom.residu
                                          , atom.charge, atom.mass
                                          , atomtype.epsilon, atomtype.sigma
                                          , double.NaN, double.NaN
                                          , atom, atomtype
                                          );
                    uatom.Coord = pdb.atoms[i].coord;
                    atoms.Add(uatom);
                }

                // bonds
                Bonds bonds = new Bonds();

                for (int i = 0; i < top_bonds.Count; i++)
                {
                    int idx0 = top_bonds[i].ai - 1; Atom atom0 = atoms[idx0]; string type0 = atom0.AtomType;
                    int idx1 = top_bonds[i].aj - 1; Atom atom1 = atoms[idx1]; string type1 = atom1.AtomType;
                    List <Gromacs.Top.Bondtypes> bondtypes = FindTypes(top_bondtypes, type0, type1);
                    //Debug.Assert(bondtypes.Count == 1);
                    Gromacs.Top.Bondtypes bondtype         = bondtypes.Last();
                    //Gromacs.Top.Bondtypes bondtype = top_bondtypes[Gromacs.Top.Bondtypes.GetStringKey(type0,type1)];
                    Bond bond = new Bond(atom0, atom1, bondtype.kb, bondtype.b0, bondtype);
                    bonds.Add(bond);
                    atom0.Bonds.Add(bond); atom0.Inter123.Add(atom1); atom0.Inter12.Add(atom1);
                    atom1.Bonds.Add(bond); atom1.Inter123.Add(atom0); atom1.Inter12.Add(atom0);
                }

                // angles
                Angles angles = new Angles();

                for (int i = 0; i < top_angles.Count; i++)
                {
                    int idx0 = top_angles[i].ai - 1; Atom atom0 = atoms[idx0]; string type0 = atom0.AtomType;
                    int idx1 = top_angles[i].aj - 1; Atom atom1 = atoms[idx1]; string type1 = atom1.AtomType;
                    int idx2 = top_angles[i].ak - 1; Atom atom2 = atoms[idx2]; string type2 = atom2.AtomType;
                    List <Gromacs.Top.Angletypes> angletypes = FindTypes(top_angletypes, type0, type1, type2);
                    //Debug.Assert(angletypes.Count == 1);
                    Gromacs.Top.Angletypes angletype         = angletypes.Last();
                    //Gromacs.Top.Angletypes angletype = top_angletypes[Gromacs.Top.Bondtypes.GetStringKey(type0, type1, type2)];
                    Angle angle = new Angle(atom0, atom1, atom2
                                            , angletype.cth, angletype.th0, angletype.cub, angletype.ub0
                                            , angletype
                                            );
                    angles.Add(angle);
                    atom0.Angles.Add(angle); atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2);
                    atom1.Angles.Add(angle); atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom0);
                    atom2.Angles.Add(angle); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                }

                // dihedrals
                Dihedrals dihedrals = new Dihedrals();
                Impropers impropers = new Impropers();

                for (int i = 0; i < top_dihedral.Count; i++)
                {
                    int idx0 = top_dihedral[i].ai - 1; Atom atom0 = atoms[idx0]; string type0 = atom0.AtomType;
                    int idx1 = top_dihedral[i].aj - 1; Atom atom1 = atoms[idx1]; string type1 = atom1.AtomType;
                    int idx2 = top_dihedral[i].ak - 1; Atom atom2 = atoms[idx2]; string type2 = atom2.AtomType;
                    int idx3 = top_dihedral[i].al - 1; Atom atom3 = atoms[idx3]; string type3 = atom3.AtomType;
                    int funct = top_dihedral[i].funct;
                    List <Gromacs.Top.Dihedraltypes> dihedraltypes = FindTypes(top_dihedraltypes, type0, type1, type2, type3);
                    {
                        List <Gromacs.Top.Dihedraltypes> ldihedraltypes = new List <Top.Dihedraltypes>(dihedraltypes);
                        // select funct matching to its query
                        for (int j = 0; j < ldihedraltypes.Count;)
                        {
                            if (ldihedraltypes[j].func == funct)
                            {
                                j++;
                            }
                            else
                            {
                                ldihedraltypes.RemoveAt(j);
                            }
                        }
                        // if there are no matching query but improper, select the improper
                        if ((ldihedraltypes.Count == 0) && (dihedraltypes[0].func == 2))
                        {
                            ldihedraltypes.Add(dihedraltypes[0]);
                        }
                        dihedraltypes = new List <Top.Dihedraltypes>(ldihedraltypes);
                    }
                    //{
                    //    // if dihedral(func==9) and improper(func==2) are mixed
                    //    // select only improper
                    //    bool has_func_2 = false;
                    //    for(int j=0; j<dihedraltypes.Count; j++)
                    //        if(dihedraltypes[j].func == 2)
                    //            has_func_2 = true;
                    //    if(has_func_2)
                    //    {
                    //        for(int j=0; j<dihedraltypes.Count; )
                    //        {
                    //            if(dihedraltypes[j].func == 2)
                    //                j++;
                    //            else
                    //                dihedraltypes.RemoveAt(j);
                    //        }
                    //    }
                    //}
                    if (dihedraltypes[0].func == 9)
                    {
                        // dihedral
                        for (int j = 1; j < dihedraltypes.Count; j++)
                        {
                            HDebug.Assert(dihedraltypes[0].func == dihedraltypes[j].func);
                            HDebug.Assert(dihedraltypes[0].i.Trim() == dihedraltypes[j].i.Trim());
                            HDebug.Assert(dihedraltypes[0].j.Trim() == dihedraltypes[j].j.Trim());
                            HDebug.Assert(dihedraltypes[0].k.Trim() == dihedraltypes[j].k.Trim());
                            HDebug.Assert(dihedraltypes[0].l.Trim() == dihedraltypes[j].l.Trim());
                        }
                        Gromacs.Top.Dihedraltypes dihedraltype = dihedraltypes.Last();
                        Dihedral dihedral = new Dihedral(atom0, atom1, atom2, atom3
                                                         , dihedraltype.cp, dihedraltype.mult, dihedraltype.phi0
                                                         , dihedraltype
                                                         );
                        dihedrals.Add(dihedral);
                        atom0.Dihedrals.Add(dihedral); //atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom0.Inter123.Add(atom3);
                        atom1.Dihedrals.Add(dihedral); //atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom3); atom1.Inter123.Add(atom0);
                        atom2.Dihedrals.Add(dihedral); //atom2.Inter123.Add(atom3); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                        atom3.Dihedrals.Add(dihedral); //atom3.Inter123.Add(atom0); atom3.Inter123.Add(atom1); atom3.Inter123.Add(atom2);
                        continue;
                    }
                    if (dihedraltypes[0].func == 2)
                    {
                        // improper
                        for (int j = 1; j < dihedraltypes.Count; j++)
                        {
                            HDebug.Assert(dihedraltypes[0].func == dihedraltypes[j].func);
                            HDebug.Assert(dihedraltypes[0].i.Trim() == dihedraltypes[j].i.Trim());
                            HDebug.Assert(dihedraltypes[0].j.Trim() == dihedraltypes[j].j.Trim());
                            HDebug.Assert(dihedraltypes[0].k.Trim() == dihedraltypes[j].k.Trim());
                            HDebug.Assert(dihedraltypes[0].l.Trim() == dihedraltypes[j].l.Trim());
                        }
                        Gromacs.Top.Dihedraltypes impropertype = dihedraltypes.Last();
                        Improper improper = new Improper(atom0, atom1, atom2, atom3
                                                         , impropertype.cp, impropertype.phi0
                                                         , impropertype
                                                         );
                        impropers.Add(improper);
                        atom0.Impropers.Add(improper); //atom0.Inter123.Add(atom1); atom0.Inter123.Add(atom2); atom0.Inter123.Add(atom3);
                        atom1.Impropers.Add(improper); //atom1.Inter123.Add(atom2); atom1.Inter123.Add(atom3); atom1.Inter123.Add(atom0);
                        atom2.Impropers.Add(improper); //atom2.Inter123.Add(atom3); atom2.Inter123.Add(atom0); atom2.Inter123.Add(atom1);
                        atom3.Impropers.Add(improper); //atom3.Inter123.Add(atom0); atom3.Inter123.Add(atom1); atom3.Inter123.Add(atom2);
                        continue;
                    }
                    HDebug.Assert(false);


                    //Debug.Assert(dihedraltypes.Count == 1);
                    //
                    //for(int j=0; j<dihedraltypes.Count; j++)
                    //    if(dihedraltypes[j].func != 2)
                    //        dihedraltype = dihedraltypes[j];
                    //Debug.Assert(dihedraltype != null);
                    //List<Gromacs.Top.Dihedraltypes> dihedraltypes = top_dihedraltypes[Gromacs.Top.Dihedraltypes.GetStringKey(type0, type1, type2, type3)];
                }

                // 1-4 interactions
                for (int i = 0; i < atoms.Count; i++)
                {
                    HashSet <Atom> Inter14 = new HashSet <Atom>();
                    BuildInter1toN(atoms[i], 4, Inter14); // find all atoms for 1-4 interaction
                    Inter14.Remove(atoms[i]);             // remove self
                    foreach (Atom atom in atoms[i].Inter123)
                    {
                        Inter14.Remove(atom);             // remove all 1-2, 1-3 interactions
                    }
                    atoms[i].Inter14 = Inter14;
                }
                Nonbonded14s nonbonded14s = new Nonbonded14s();

                nonbonded14s.Build(atoms);

                //// nonbondeds
                //// do not make this list in advance, because it depends on the atom positions
                //Nonbondeds nonbondeds = new Nonbondeds();
                //nonbondeds.Build(atoms);


                //Universe univ = new Universe();
                univ.pdb = pdb;
                univ.refs.Add("top", top);
                univ.atoms     = atoms;
                univ.bonds     = bonds;
                univ.angles    = angles;
                univ.dihedrals = dihedrals;
                univ.impropers = impropers;
                //univ.nonbondeds   = nonbondeds  ;  // do not make this list in advance, because it depends on the atom positions
                univ.nonbonded14s = nonbonded14s;

                HDebug.Assert(univ.Verify());
                return(univ);
            }
示例#21
0
        public static Boolean makeApproval(TNF tnf, User user, Notification noti, string remarks)
        {
            //check TNF status
            if (!tnf.getStatus().ToLower().Equals("pending"))
            {
                return(false);
            }

            //check budget
            Department currentDept   = deptDAO.getDeptByName(tnf.getUser().getDepartment());
            Course     currentCourse = tnfDAO.getCourseFromTNF(tnf.getTNFID());
            double     courseCost    = currentCourse.getPrice();
            Boolean    gotBudget     = deptDAO.checkDeptBudget(currentDept.getDeptName(), currentCourse.getPrice());
            int        nextWFLevel   = 0;

            if (!gotBudget)
            {
                return(false);
            }

            //check if approver is last in chain
            Boolean          isLastApprover  = false;
            Workflow         currentWorkflow = tnf.getWorkflow();
            WorkflowSub      currentWFS      = tnf.getWorkflowSub();
            WorkflowApprover nextApprover    = new WorkflowApprover();

            WorkflowApprover        lastApprover = wfaDAO.getLastApproverInChain(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
            List <WorkflowApprover> approvers    = wfaDAO.getSortedWorkflowApprovers(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());

            if (user.getJobCategory().Contains(lastApprover.getJobCategory()))
            {
                isLastApprover = true;
            }
            else if (lastApprover.getJobCategory().Equals("superior"))
            {
                User currentTNFUser = tnf.getUser();
                if (currentTNFUser.getSupervisor().Equals(user.getUserID()))
                {
                    isLastApprover = true;
                }
            }
            else
            {
                int levelOfUser = wfaDAO.getLevelByJobCategory(user.getJobCategory(), currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                if (levelOfUser == -1)
                {
                    nextApprover = lastApprover;
                    nextWFLevel  = lastApprover.getLevel();
                }
                else
                {
                    nextApprover = approvers[levelOfUser + 1];
                    nextWFLevel  = levelOfUser + 1;
                }
            }

            //If its HR, approve for all HR
            List <User>         allHR             = userDAO.getAllHR();
            List <Notification> allHRNotification = new List <Notification>();

            foreach (User hr in allHR)
            {
                allHRNotification.Add(notificationDAO.getPendingNotificationByTnfIDandUserID(tnf.getTNFID(), hr.getUserID()));
            }
            allHRNotification = allHRNotification.Where(x => x != null).ToList();
            if (allHRNotification.Count < 2)
            {
                if (isLastApprover)
                {
                    notificationDAO.updateNotificationStatus(noti.getNotificationID(), "approved");
                    notificationDAO.updateNotificationApprovedDate(noti.getNotificationID());
                    if (remarks != null)
                    {
                        notificationDAO.updateNotificationRemarks(noti.getNotificationID(), remarks);
                    }
                    tnfDAO.updateTNFStatus(tnf.getTNFID(), "approved");
                    deptDAO.updateDeptBudget(currentDept.getDeptName(), (currentDept.getActualBudget() - currentCourse.getPrice()));
                    double bondCriteria = currentWorkflow.getBondCriteria();
                    if (currentCourse.getPrice() >= bondCriteria)
                    {
                        Bonds currentBond = bondDAO.getBondByTNFIDandUserID(tnf.getTNFID(), tnf.getUser().getUserID());
                        bondDAO.updateBondStatus(currentBond.getBondID(), "approved");
                    }
                }
                else
                {
                    notificationDAO.updateNotificationStatus(noti.getNotificationID(), "approved");
                    notificationDAO.updateNotificationApprovedDate(noti.getNotificationID());
                    if (remarks != null)
                    {
                        notificationDAO.updateNotificationRemarks(noti.getNotificationID(), remarks);
                    }
                    tnfDAO.updateTNFWFStatus(tnf.getTNFID(), nextWFLevel);
                    tnf = tnfDAO.getIndividualTNFByID(tnf.getUser().getUserID(), tnf.getTNFID());
                    Workflow_Route.sendApprovalNotification(tnf, nextApprover);
                }
            }
            else
            {
                if (isLastApprover)
                {
                    foreach (Notification hrNoti in allHRNotification)
                    {
                        notificationDAO.updateNotificationStatus(hrNoti.getNotificationID(), "approved");
                        notificationDAO.updateNotificationApprovedDate(hrNoti.getNotificationID());
                        if (remarks != null)
                        {
                            notificationDAO.updateNotificationRemarks(noti.getNotificationID(), remarks);
                        }
                    }
                    tnfDAO.updateTNFStatus(tnf.getTNFID(), "approved");
                    deptDAO.updateDeptBudget(currentDept.getDeptName(), (currentDept.getActualBudget() - currentCourse.getPrice()));
                    double bondCriteria = currentWorkflow.getBondCriteria();
                    if (currentCourse.getPrice() >= bondCriteria)
                    {
                        Bonds currentBond = bondDAO.getBondByTNFIDandUserID(tnf.getTNFID(), tnf.getUser().getUserID());
                        bondDAO.updateBondStatus(currentBond.getBondID(), "approved");
                    }
                }
                else
                {
                    foreach (Notification hrNoti in allHRNotification)
                    {
                        notificationDAO.updateNotificationStatus(hrNoti.getNotificationID(), "approved");
                        notificationDAO.updateNotificationApprovedDate(hrNoti.getNotificationID());
                        if (remarks != null)
                        {
                            notificationDAO.updateNotificationRemarks(noti.getNotificationID(), remarks);
                        }
                    }
                    tnfDAO.updateTNFWFStatus(tnf.getTNFID(), nextWFLevel);
                    tnf = tnfDAO.getIndividualTNFByID(tnf.getUser().getUserID(), tnf.getTNFID());
                    Workflow_Route.sendApprovalNotification(tnf, nextApprover);
                }
            }
            return(true);
        }
示例#22
0
 /// <summary>
 /// Add a bond to this Sgroup. The bond list
 /// </summary>
 /// <param name="bond">bond to add</param>
 public void Add(IBond bond)
 {
     Bonds.Add(bond);
 }
 private void SaveAsset(Bond bond)
 {
     Bonds.Add(bond);
     SaveChanges();
 }
示例#24
0
        public static Boolean routeIndividual(TNF tnf)
        {
            User     currentUser     = tnf.getUser();
            UserDAO  userDAO         = new UserDAO();
            Workflow currentWorkflow = wfDAO.getCurrentActiveWorkflow("individual");
            //int numOfCriteria = wfDAO.getNumberOfCriteriaByWorkflow(currentWorkflow.getWorkflowID());
            string   currentStatusOfTNF = tnf.getStatus();
            int      probationPeriod    = currentWorkflow.getProbationPeriod();
            TimeSpan ts            = DateTime.Now.Subtract(currentUser.getStartDate());
            Course   currentCourse = tnfDAO.getCourseFromTNF(tnf.getTNFID());

            List <WorkflowSub> workflowSubs;

            if (ts.TotalDays < probationPeriod)
            {
                workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "ceo");
            }
            else if (currentCourse.getOverseas().Equals("y"))
            {
                workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "ceo");
            }
            else
            {
                workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "normal");
            }

            double tnfTotalCost = tnfDAO.getCourseFromTNF(tnf.getTNFID()).getPrice(); //to get from tnfDAO and to confirm if gst is included in the fee of consideration

            if (currentStatusOfTNF.Equals("pending"))
            {
                //check bond criteria
                double bondCriteria = currentWorkflow.getBondCriteria();
                if (tnfTotalCost >= bondCriteria)
                {
                    //create new bond object
                    BondDAO  bondDAO       = new BondDAO();
                    Bonds    newBond       = new Bonds(currentUser.getUserID(), tnf.getTNFID(), "pending");
                    int      bondID        = bondDAO.createBond(newBond);
                    DateTime bondStartDate = currentCourse.getEndDate();
                    bondStartDate = bondStartDate.AddDays(1);
                    bondDAO.updateBondStartDate(bondID, bondStartDate);
                }

                for (int i = 0; i < workflowSubs.Count; i++)
                {
                    if (wfsDAO.getWorkflowSubType(workflowSubs[i].getWorkflowSubID()).Equals("superior"))
                    {
                        i = 0;
                    }
                    WorkflowSub             currentWFS = workflowSubs[i];
                    double                  low_limit  = currentWFS.getAmount_low();
                    double                  high_limit = currentWFS.getAmount_high();
                    List <WorkflowApprover> approvers  = wfaDAO.getSortedWorkflowApprovers(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                    if (tnfTotalCost >= low_limit && tnfTotalCost <= high_limit)
                    {
                        WorkflowApprover currentWFApprover        = approvers[tnf.getWFStatus()];
                        string           currentUser_job_category = currentUser.getJobCategory();
                        WorkflowApprover checkApprover            = wfaDAO.getWorkflowApproverByJobCategory(currentUser_job_category, currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                        Boolean          checkIfLevelHigher       = checkJobLevelHigher(currentUser_job_category, currentWFApprover.getJobCategory());
                        //to check if applicant's level is higher than approver's level (need to write another function to check)
                        WorkflowApprover lastWFApprover = wfaDAO.getLastApproverInChain(currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                        int levelOfUser = wfaDAO.getLevelByJobCategory(currentUser.getJobCategory(), currentWorkflow.getWorkflowID(), currentWFS.getWorkflowSubID());
                        if (checkApprover.getJobCategory() == null)
                        {
                            if (!checkIfLevelHigher)
                            {
                                tnfDAO.updateTNFWFSub(tnf.getTNFID(), currentWFS.getWorkflowSubID());
                                sendApprovalNotification(tnf, currentWFApprover);
                                return(true);
                            }
                            else
                            {
                                Boolean checkIfLevelHigherThanLastApprover = checkJobLevelHigher(currentUser_job_category, lastWFApprover.getJobCategory());
                                if (!checkIfLevelHigherThanLastApprover)
                                {
                                    for (int j = 0; i < approvers.Count; j++)
                                    {
                                        Boolean checkLevelWithCurrentApprover = checkJobLevelHigher(currentUser_job_category, approvers[j].getJobCategory());
                                        if (checkLevelWithCurrentApprover)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            WorkflowApprover nextWFApprover = approvers[j];
                                            tnfDAO.updateTNFWFStatus(tnf.getTNFID(), j);
                                            tnfDAO.updateTNFWFSub(tnf.getTNFID(), currentWFS.getWorkflowSubID());
                                            sendApprovalNotification(tnf, nextWFApprover);
                                            return(true);
                                        }
                                    }
                                }
                                else
                                {
                                    workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "superior");
                                }
                            }
                        }
                        else
                        {
                            if (!currentUser.getJobCategory().Equals("ceo"))
                            {
                                if (levelOfUser < lastWFApprover.getLevel())
                                {
                                    WorkflowApprover nextWFApprover = approvers[levelOfUser + 1];
                                    tnfDAO.updateTNFWFSub(tnf.getTNFID(), currentWFS.getWorkflowSubID());
                                    tnfDAO.updateTNFWFStatus(tnf.getTNFID(), levelOfUser + 1);
                                    sendApprovalNotification(tnf, nextWFApprover);
                                    return(true);
                                }
                                else
                                {
                                    //handle last person in chain
                                    workflowSubs = wfsDAO.getSortedWorflowSubByWorkflowIDandType(currentWorkflow.getWorkflowID(), "superior");
                                }
                            }
                            else
                            {
                                //no need handle CEO
                            }
                        }
                    }
                }
            }
            return(false);
        }