示例#1
0
        public static bool GetModesSelftest()
        {
            if (GetModesSelftest_DoTest == false)
            {
                return(true);
            }
            GetModesSelftest_DoTest = false;

            string pdbpath = @"C:\Users\htna\htnasvn_htna\VisualStudioSolutions\Library2\HTLib2.Bioinfo\Bioinfo.Data\pdb\1MJC.pdb";

            if (HFile.Exists(pdbpath) == false)
            {
                return(false);
            }

            Pdb pdb = Pdb.FromFile(pdbpath);

            for (int i = 0; i < pdb.atoms.Length; i++)
            {
                HDebug.Assert(pdb.atoms[0].altLoc == pdb.atoms[i].altLoc);
                HDebug.Assert(pdb.atoms[0].chainID == pdb.atoms[i].chainID);
            }
            List <Vector> coords = pdb.atoms.ListCoord();
            double        cutoff = 13;
            Matrix        hess   = Hess.GetHessAnm(coords.ToArray(), cutoff).ToArray();

            Matrix modes;
            Vector freqs;

            GetModes(hess, out modes, out freqs);

            return(true);
        }
示例#2
0
        public static Pdb GetPdb(string pdbid, bool forceToRedownload = false)
        {
            List <string> pdblines = GetPdbLines(pdbid, forceToRedownload);
            Pdb           pdb      = Pdb.FromLines(pdblines);

            return(pdb);
        }
示例#3
0
            public static Universe Build(string pdbpath, string toppath, ITextLogger logger)
            {
                Pdb pdb = Pdb.FromFile(pdbpath);
                Top top = Top.FromFile(toppath);

                return(Build(pdb, top, logger));
            }
示例#4
0
                public Pdb GetPdb()
                {
                    Pdb pdb = PdbDatabase.GetPdb(pdbid);

                    pdb = pdb.GetNoAltloc();
                    return(pdb);
                }
示例#5
0
        public static CPsfgenExt PsfgenExt
            (Pdb pdb
            , string[] toplines
            , string[] parlines
            , Pdb alignto
            , HOptions options
            )
        {
            string[] psfgen_lines = null;
            List <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms = new List <Tuple <string, string, Pdb.IAtom[]> >();
            var pdb_iatoms = pdb.iatoms;

            foreach (var ch_iatoms in pdb_iatoms.GroupChainID())
            {
                lstSegFileAtoms.Add(new Tuple <string, string, Pdb.IAtom[]>
                                        (ch_iatoms.Key + ""
                                        , null
                                        , ch_iatoms.Value.ToArray()
                                        ));
            }
            return(PsfgenExt
                       (lstSegFileAtoms, toplines, parlines, alignto, psfgen_lines
                       , options: options
                       ));
        }
示例#6
0
        public Pdb GetNoAltloc()
        {
            Pdb pdb = this.Clone();

            char[] toremove = pdb.atoms.ListAltLoc().HListCommonT().ToArray();
            toremove = toremove.HRemoveAll(' ');
            if (toremove.Length >= 1)
            {
                toremove = toremove.HRemoveAll(toremove[0]);
            }

            for (int i = 0; i < pdb.elements.Length; i++)
            {
                char?altLoc = null;
                if (pdb.elements[i] is Pdb.Atom)
                {
                    altLoc = (pdb.elements[i] as Pdb.Atom).altLoc;
                }
                if (pdb.elements[i] is Pdb.Hetatm)
                {
                    altLoc = (pdb.elements[i] as Pdb.Hetatm).altLoc;
                }

                if ((altLoc != null) && toremove.Contains(altLoc.Value))
                {
                    pdb.elements[i] = null;
                }
            }

            pdb = new Pdb(pdb.elements);
            return(pdb);
        }
示例#7
0
            public static void GetEnergies(AlignData data1, IList <Vector> coords2
                                           , out double pot_rmsd, out double pot_enrg, out double pot_enrg_full, out double pot_enrg_anisou
                                           , Pdb pdb2           = null
                                           , string pdb2outpath = null
                                           )
            {
                Anisou[] anisous1;// = data1.GetAnisous();
                double[] bfactor1;
                {
                    List <Mode> modes = new List <Mode>(data1.GetModes());
                    for (int i = 0; i < 6; i++)
                    {
                        modes.RemoveAt(0);
                    }
                    bfactor1 = HBioinfo.GetBFactor(modes.ToArray(), data1.masses);
                    HDebug.Assert(data1.size == bfactor1.Length);
                    anisous1 = Anisou.FromBFactor(bfactor1, scale: 10000 * 1000);
                }
                //Trans3 trans = MinAnisou.GetTrans(data1.coords, anisous1, coords2);
                Trans3        trans        = GetTrans(data1.coords, bfactor1, coords2);
                List <Vector> coords2trans = new List <Vector>(trans.GetTransformed(coords2));

                if (pdb2 != null && pdb2outpath != null)
                {
                    data1.pdb.ToFile(pdb2outpath, coords2trans, anisous: anisous1.GetUs());
                }

                pot_rmsd        = data1.GetRmsdFrom(coords2trans);
                pot_enrg        = data1.GetEnergyFromDiag(coords2trans);
                pot_enrg_full   = data1.GetEnergyFromFull(coords2trans);
                pot_enrg_anisou = data1.GetEnergyFromAnisou(coords2trans);
            }
 public static void SelectCommonAtoms(Pdb pdb1, string ChainIDs1, out List <Atom> atoms1
                                      , Pdb pdb2, string ChainIDs2, out List <Atom> atoms2
                                      )
 {
     SelectCommonAtoms(pdb1.atoms, ChainIDs1, out atoms1
                       , pdb2.atoms, ChainIDs2, out atoms2
                       );
 }
示例#9
0
            public static Universe Build(Tinker.Xyz xyz, Tinker.Prm prm, Pdb pdb0, Tinker.Xyz xyz0, double tolCoordPdbXyz /*=0.002*/)
            {
                Universe univ = Build(xyz0, prm, pdb0, tolCoordPdbXyz);

                Vector[] coords = xyz.atoms.HListCoords();
                univ.SetCoords(coords);
                return(univ);
            }
示例#10
0
            public static void Align(string pdbpath1, string pdbpath2, string alignedpath2)
            {
                Pdb pdb1 = Pdb.FromFile(pdbpath1); List <Pdb.Atom> atoms1 = pdb1.atoms.SelectByChainID().SelectByAltLoc();
                Pdb pdb2 = Pdb.FromFile(pdbpath2); List <Pdb.Atom> atoms2 = pdb2.atoms.SelectByChainID().SelectByAltLoc();

                Align(atoms1, ref atoms2);

                Pdb.ToFile(alignedpath2, atoms2);
            }
示例#11
0
            public static AlignData FromFiles(string path_pdb, string path_hess, IList <double> masses, string cachebase = null)
            {
                AlignData data = new AlignData();

                data.pdb       = Pdb.FromFile(path_pdb);
                data.coords    = data.pdb.atoms.ListCoord();
                data.cachebase = cachebase;
                int n = data.coords.Count;

                {   // data.hess
                    List <string> lines = HFile.ReadLines(path_hess).ToList();
                    int           row, col;
                    {
                        string[] tokens = lines[1].Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        HDebug.Assert(tokens.Length == 2);
                        row = int.Parse(tokens[0]);
                        col = int.Parse(tokens[1]);
                        HDebug.Assert(row == col);
                    }
                    HDebug.Assert(row == n * 3, col == n * 3);
                    MatrixByArr[,] hess = new MatrixByArr[n, n];
                    for (int c = 0; c < n; c++)
                    {
                        for (int r = 0; r < n; r++)
                        {
                            hess[c, r] = new double[3, 3];
                        }
                    }
                    for (int c = 0; c < col; c++)
                    {
                        string   line   = lines[c + 2];
                        string[] tokens = line.Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        HDebug.Assert(tokens.Length == row);
                        for (int r = 0; r < row; r++)
                        {
                            double val = double.Parse(tokens[r]);
                            hess[c / 3, r / 3][c % 3, r % 3] += val;
                            hess[r / 3, c / 3][r % 3, c % 3] += val;
                        }
                    }
                    for (int c = 0; c < n; c++)
                    {
                        for (int r = 0; r < n; r++)
                        {
                            hess[c, r] /= 2;
                        }
                    }
                    data.hess = hess;
                }

                data.masses = masses.ToArray();

                return(data);
            }
示例#12
0
        static Pdb PsfgenExt_AlignTo(Pdb pdb, Pdb alignto)
        {
            var           dictpdb  = pdb.atoms.SelectByName("CA").GroupChainIDResSeq();
            var           dictaln  = alignto.atoms.SelectByName("CA").GroupChainIDResSeq();
            List <Vector> coordpdb = new List <Vector>();
            List <Vector> coordaln = new List <Vector>();

            foreach (char ch in dictpdb.Keys)
            {
                if (dictaln.ContainsKey(ch) == false)
                {
                    continue;
                }
                foreach (var resi in dictpdb[ch].Keys)
                {
                    var atompdb = dictpdb[ch][resi];
                    if (atompdb.Count != 1)
                    {
                        throw new HException(string.Format(">1 number of CA in chain {0} resi {1} in atompdb", ch, resi));
                    }
                    if (dictaln[ch].ContainsKey(resi) == false)
                    {
                        continue;
                    }
                    var atomaln = dictaln[ch][resi];
                    if (atomaln.Count != 1)
                    {
                        throw new HException(string.Format(">1 number of CA in chain {0} resi {1} in atomaln", ch, resi));
                    }
                    HDebug.Assert(coordpdb.Count == coordaln.Count);
                    coordpdb.Add(atompdb[0].coord);
                    coordaln.Add(atomaln[0].coord);
                }
            }

            var trans = Align.MinRMSD.GetTrans(coordaln, coordpdb);

            Dictionary <Pdb.IAtom, Vector> newcoords = new Dictionary <Pdb.IAtom, Vector>();

            foreach (var atom in pdb.atoms)
            {
                newcoords.Add(atom, trans.DoTransform(atom.coord));
            }
            foreach (var atom in pdb.hetatms)
            {
                newcoords.Add(atom, trans.DoTransform(atom.coord));
            }

            var npdb = pdb.CloneUpdateCoord(newcoords);

            return(npdb);
        }
示例#13
0
 public static void SelfTest(string rootpath, string[] args)
 {
     {
         Pdb           pdb    = Pdb.FromFile(rootpath + @"\Sample\alanin.pdb");
         List <Vector> coords = pdb.atoms.ListCoord();
         coords[0] = new Vector(0, 1, 2);
         pdb.ToFile(rootpath + @"\Sample\alanin.updated.pdb", coords);
     }
     {
         Pdb pdb = Pdb.FromFile(rootpath + @"\Sample\1a6g.pdb");
         //pdb.CollectResidues();
     }
 }
示例#14
0
 public static HMutation[] FromPdb(string wtpdbid, IList <string> pdbids, Func <string, Pdb> FnLoadPdb)
 {
     HMutation[] mutations = new HMutation[pdbids.Count];
     for (int i = 0; i < pdbids.Count; i++)
     {
         Pdb wtpdb  = FnLoadPdb(wtpdbid);
         Pdb mutpdb = FnLoadPdb(pdbids[i]);
         mutations[i] = FromPdb
                            (wtpdb, mutpdb
                            , wt_pdbid: wtpdbid
                            , mut_pdbid: pdbids[i]
                            );
     }
     return(mutations);
 }
示例#15
0
        public static Pdb FromPdbid
            (string pdbid
            , string cachebase  // null or @"K:\PdbUnzippeds\$PDBID$.pdb"
            , bool?download     // null or false
            )
        {
            if (cachebase == null)
            {
                cachebase = @"K:\PdbUnzippeds\$PDBID$.pdb";
            }
            if (download == null)
            {
                download = false;
            }

            string pdbpath = cachebase.Replace("$PDBID$", pdbid);

            if (HFile.Exists(pdbpath))
            {
                var pdb  = Pdb.FromFile(pdbpath);
                var last = pdb.elements.Last();
                if (last is Pdb.End)
                {
                    return(pdb);
                }
                if (last.line.Length == 80)
                {
                    return(pdb);
                }

                if (download.Value)
                {   // redownload
                    pdb = Pdb.FromPdbid(pdbid);
                    pdb.ToFile(pdbpath);
                }
                return(pdb);
            }
            else if (download.Value)
            {
                Pdb pdb = Pdb.FromPdbid(pdbid);
                if (pdb != null)
                {
                    pdb.ToFile(pdbpath);
                    return(pdb);
                }
            }
            return(null);
        }
示例#16
0
        //public static PdbInfo GetPdbInfo(string pdbid, string pdbpath)
        //{
        //    if(HFile.Exists(pdbpath) == false)
        //        Pdb.FromPdbid(pdbid, cachepath: pdbpath);
        //    Pdb pdb = Pdb.FromFile(pdbpath);
        //    return GetPdbInfo(pdbid, pdb);
        //}
        //static PdbInfo GetPdbInfo(Pdb pdb)
        //{
        //    return GetPdbInfo("", pdb);
        //}
        static PdbInfo GetPdbInfo(string pdbid, Pdb pdb)
        {
            PdbInfo pdbinfo = new PdbInfo
            {
                pdbid      = pdbid,
                keywords   = pdb.elements.ListType <Pdb.Keywds>().ListKeyword().ToArray(),
                numAtom    = pdb.atoms.Length,
                numAnisou  = pdb.anisous.Length,
                numModel   = pdb.elements.ListType <Pdb.Model>().Count,
                numChain   = pdb.atoms.ListChainID().HListCommonT().Count,
                numAltloc  = pdb.atoms.ListAltLoc().HListCommonT().Count,
                numResidue = pdb.atoms.ListResSeq().HListCommonT().Count,
            };

            return(pdbinfo);
        }
示例#17
0
        public static void PCA(string pdbpath, string outpathroot, double scaleAnimation)
        {
            HDebug.ToDo();

            Pdb.Atom[] meanconf;
            Matrix     modes;
            Vector     freq;

            PCA(pdbpath, out meanconf, out modes, out freq);

            for (int i = 0; i < freq.Size; i++)
            {
                string   outpath = outpathroot + i.ToString("00") + ".pdb";
                Vector[] mode    = (modes.GetColVector(i) * scaleAnimation / freq[i]).ToVectors(3);
                Pdb.ToFileAnimated(outpath, meanconf, mode);
            }
        }
        public static Pdb CopyPdbOccupancyForMergedPsf(Pdb copyto, Pdb copyfrom1, Pdb copyfrom2)
        {
            KDTreeDLL.KDTree <Pdb.Atom> kdtree = new KDTreeDLL.KDTree <Pdb.Atom>(3);
            foreach (var atom in copyfrom1.atoms)
            {
                kdtree.insert(atom.coord, atom);
            }
            foreach (var atom in copyfrom2.atoms)
            {
                kdtree.insert(atom.coord, atom);
            }

            Pdb pdb = copyto.Clone();

            List <string> nlines = new List <string>();

            for (int i = 0; i < pdb.elements.Length; i++)
            {
                var elemi = pdb.elements[i];
                if ((elemi is Pdb.Atom) == false)
                {
                    nlines.Add(elemi.line);
                }
                else
                {
                    var atomi = elemi as Pdb.Atom;
                    var atomx = kdtree.nearest(atomi.coord);
                    HDebug.Assert(atomi.coord[0] == atomx.coord[0]);
                    HDebug.Assert(atomi.coord[1] == atomx.coord[1]);
                    HDebug.Assert(atomi.coord[2] == atomx.coord[2]);
                    /// 55 - 60        Real(6.2)     occupancy    Occupancy.
                    char[] line = atomi.line.ToCharArray();
                    line[55 - 1] = atomx.line[55 - 1];
                    line[56 - 1] = atomx.line[56 - 1];
                    line[57 - 1] = atomx.line[57 - 1];
                    line[58 - 1] = atomx.line[58 - 1];
                    line[59 - 1] = atomx.line[59 - 1];
                    line[60 - 1] = atomx.line[60 - 1];
                    string nline = line.HToString();
                    nlines.Add(nline);
                    Pdb.Atom natomi = Pdb.Atom.FromString(nline);
                    pdb.elements[i] = natomi;
                }
            }
            return(pdb);
        }
示例#19
0
        public double GetRMSD(Pdb pdb, char selAltLoc = 'A', bool includeHydrogen = false)
        {
            List <Tuple <int, int> > idxs_univ2pdb = GetIndex(pdb, selAltLoc, includeHydrogen);

            List <int>    atomidxs   = new List <int>();
            List <Vector> atomcoords = new List <Vector>();

            foreach (Tuple <int, int> idx_univ2pdb in idxs_univ2pdb)
            {
                int    atomidx   = idx_univ2pdb.Item1;
                Vector atomcoord = pdb.atoms[idx_univ2pdb.Item2].coord;
                atomidxs.Add(atomidx);
                atomcoords.Add(atomcoord);
            }

            return(GetRMSD(atomidxs, atomcoords));
        }
示例#20
0
        public Pdb CloneByRemoveHeader()
        {
            Pdb pdb = CloneSelectType
                      //( "TITLE "
                      //, "REMARK"
                      //, "CRYST1"
                          ("MODEL "
                          , "ATOM  "
                          , "TER   "
                          , "ENDMDL"
                          , "ANISOU"
                          , "HETATM"
                          , "SIGUIJ"
                          , "CONECT"
                          );

            return(pdb);
        }
示例#21
0
        public Pdb CloneRemoveHetatm()
        {
            Pdb pdb = CloneSelectType
                          (null
                          , "HEADER", "TITLE", "COMPND", "SOURCE", "KEYWDS", "EXPDTA", "AUTHOR", "REVDAT", "JRNL", "REMARK"    //
                          , "DBREF", "SEQRES", "SEQADV"                                                                        //
                          , "HET", "HETNAM", "FORMUL"                                                                          //
                          , "HELIX", "SHEET"                                                                                   //
                          , "LINK"                                                                                             //
                          , "SITE"                                                                                             //
                          , "CRYST1", "ORIGX1", "ORIGX2", "ORIGX3", "SCALE1", "SCALE2", "SCALE3", "MTRIX1", "MTRIX2", "MTRIX3" //
                          , "MODEL", "ATOM", "ANISOU", "SIGUIJ", "TER", "ENDMDL"                                               // , "HETATM"
                          , "CONECT"                                                                                           //
                          , "MASTER", "END"                                                                                    //
                          );

            return(pdb);
        }
示例#22
0
            public static void GetEnergies(AlignData data1, IList <Vector> coords2
                                           , out double geo_rmsd, out double geo_enrg, out double geo_enrg_full, out double geo_enrg_anisou
                                           , Pdb pdb2, string pdb2outpath
                                           )
            {
                Trans3        trans        = GetTrans(data1.coords, coords2);
                List <Vector> coords2trans = new List <Vector>(trans.GetTransformed(coords2).ToArray());

                if (pdb2 != null && pdb2outpath != null)
                {
                    pdb2.ToFile(pdb2outpath, coords2);
                }

                geo_rmsd        = data1.GetRmsdFrom(coords2trans);
                geo_enrg        = data1.GetEnergyFromDiag(coords2trans);
                geo_enrg_full   = data1.GetEnergyFromFull(coords2trans);
                geo_enrg_anisou = data1.GetEnergyFromAnisou(coords2trans);
            }
示例#23
0
            public static HMutation FromPdb
                (Pdb wtpdb, Pdb mutpdb
                , string wt_pdbid   = null, string mut_pdbid    = null
                , int?wt_pdb_model  = null, char?wt_pdb_altLoc  = null, char?wt_pdb_chainID  = null, char?wt_pdb_iCode  = null
                , int?mut_pdb_model = null, char?mut_pdb_altLoc = null, char?mut_pdb_chainID = null, char?mut_pdb_iCode = null
                )
            {
                if ((wtpdb.models.Length >= 2) && wt_pdb_model == null)
                {
                    wt_pdb_model = 0;
                }                                                                             // HDebug.Assert(false);
                if ((mutpdb.models.Length >= 2) && mut_pdb_model == null)
                {
                    mut_pdb_model = 0;
                }                                                                             // HDebug.Assert(false);

                Pdb.Atom[]            wt_atoms      = wtpdb.SelectAtoms(imodel: wt_pdb_model, altLoc: wt_pdb_altLoc, chainID: wt_pdb_chainID, iCode: wt_pdb_iCode);
                Pdb.Atom[]            mut_atoms     = mutpdb.SelectAtoms(imodel: mut_pdb_model, altLoc: mut_pdb_altLoc, chainID: mut_pdb_chainID, iCode: mut_pdb_iCode);
                Pdb.Residue[]         wt_resis      = wt_atoms.ListResidue();
                Pdb.Residue[]         mut_resis     = mut_atoms.ListResidue();
                Tuple <string, int>[] wt_resn_resi  = wt_resis.HListResNameSeq();
                Tuple <string, int>[] mut_resn_resi = mut_resis.HListResNameSeq();

                Tuple <string, string, int, string>[] mutationinfos =
                    FromResnResi
                        (wt_resn_resi
                        , mut_resn_resi
                        , rngLcsLen: new Tuple <int, int>((int)(wt_resis.Length * 0.8), (int)(wt_resis.Length * 1.2))
                        );

                return(new HMutation
                {
                    wt_pdb = wtpdb, mut_pdb = mutpdb,
                    wt_pdbid = wt_pdbid, mut_pdbid = mut_pdbid,
                    wt_ResSeq = wt_resis.HListResSeq(), mut_ResSeq = mut_resis.HListResSeq(),
                    wt_ResName = wt_resis.HListResName(), mut_ResName = mut_resis.HListResName(),
                    wt_pdb_model = wt_pdb_model, mut_pdb_model = mut_pdb_model,
                    wt_pdb_altLoc = wt_pdb_altLoc, mut_pdb_altLoc = mut_pdb_altLoc,
                    wt_pdb_chainID = wt_pdb_chainID, mut_pdb_chainID = mut_pdb_chainID,
                    wt_pdb_iCode = wt_pdb_iCode, mut_pdb_iCode = mut_pdb_iCode,
                    mutationinfos = mutationinfos
                });
            }
示例#24
0
        public Pdb CloneRemoveResName(bool inAtom, bool inHetatm, params string[] resName)
        {
            HashSet <IAtom>  iatomsInConect = ListIAtomInConect().HToHashSet();
            HashSet <string> setResName     = resName.HTrim().HToHashSet();
            List <Element>   nelements      = new List <Element>();
            int numRemove         = 0;
            int numRemoveInConect = 0;

            foreach (Element element in elements)
            {
                string record = element.record.Trim();
                bool   remove = false;
                if (inAtom && record == "ATOM")
                {
                    if (resName.Contains((element as Atom).resName.Trim()))
                    {
                        remove = true;
                    }
                }
                if (inHetatm && record == "HETATM")
                {
                    if (resName.Contains((element as Hetatm).resName.Trim()))
                    {
                        remove = true;
                    }
                }
                if (remove)
                {
                    if (iatomsInConect.Contains(element as IAtom))
                    {
                        numRemoveInConect++;
                    }
                    numRemove++;
                    continue;
                }
                nelements.Add(element);
            }
            HDebug.Assert(numRemoveInConect == 0);
            Pdb npdb = new Pdb(nelements);

            return(npdb);
        }
 public static void ToPdbFileAnimated
     (this Mode mode
     , string filepath
     , Pdb pdb
     , IList <double> stepTimes = null
     , double scale             = 1
     , int?modelidx             = null
     )
 {
     Pdb.ToFileAnimated
         (filepath
         , pdb.atoms
         , mode.GetEigvecsOfAtoms(scale)
         , stepTimes
         , null
         , null
         , null
         , modelidx
         );
 }
示例#26
0
        public static bool GetBFactorSelfTest(string pdbpath, double cutoff, double corr, int round, InfoPack extra)
        {
            if (HFile.Exists(pdbpath) == false)
            {
                return(false);
            }

            Pdb pdb = Pdb.FromFile(pdbpath);

            for (int i = 0; i < pdb.atoms.Length; i++)
            {
                HDebug.Assert(pdb.atoms[0].altLoc == pdb.atoms[i].altLoc);
                HDebug.Assert(pdb.atoms[0].chainID == pdb.atoms[i].chainID);
            }
            List <Pdb.Atom> atoms = new List <Pdb.Atom>();

            for (int i = 0; i < pdb.atoms.Length; i++)
            {
                Pdb.Atom atom = pdb.atoms[i];
                if (atom.name.Trim().ToUpper() == "CA")
                {
                    atoms.Add(atom);
                }
            }
            List <Vector> coords  = atoms.ListCoord();
            Matrix        hess    = Hess.GetHessAnm(coords, cutoff);
            InfoPack      lextra  = new InfoPack();
            Vector        bfactor = GetBFactor(hess, 0.00000001, null, lextra);

            if (extra != null)
            {
                extra["num_zero_eigvals"] = lextra["num_zero_eigvals"];
                extra["eigenvalues"]      = lextra["eigenvalues"];
            }

            double corr_comp = pdb.CorrBFactor(atoms.ListName(), atoms.ListResSeq(), bfactor.ToArray());

            corr_comp = Math.Round(corr_comp, round);
            HDebug.Assert(corr == corr_comp);
            return(corr == corr_comp);
        }
示例#27
0
            //public static Trans3 GetTrans(IList<Vector> C1, Matrix[] anisou1, IList<Vector> C2)
            //{
            //    int size = C1.Count;
            //    Tuple<Vector[], double[]>[] eigs1 = new Tuple<Vector[], double[]>[size];
            //    {
            //        for(int i=0; i<size; i++)
            //        {
            //            Vector[] eigvec;
            //            double[] eigval;
            //            Debug.Verify(NumericSolver.Eig(anisou1[i], out eigvec, out eigval));
            //            {   // normalize eigval and eigvec
            //                double l;
            //                l = eigvec[0].Dist; eigvec[0] /= l; eigval[0] *= (l*l); eigval[0] = Math.Pow(eigval[0], 2); Debug.Assert(eigval[0] >= 0);
            //                l = eigvec[1].Dist; eigvec[1] /= l; eigval[1] *= (l*l); eigval[1] = Math.Pow(eigval[1], 2); Debug.Assert(eigval[1] >= 0);
            //                l = eigvec[2].Dist; eigvec[2] /= l; eigval[2] *= (l*l); eigval[2] = Math.Pow(eigval[2], 2); Debug.Assert(eigval[2] >= 0);
            //            }
            //            {
            //                eigval[0] = 1 / eigval[0];
            //                eigval[1] = 1 / eigval[1];
            //                eigval[2] = 1 / eigval[2];
            //            }
            //            eigs1[i] = new Tuple<Vector[], double[]>(eigvec, eigval);
            //        }
            //    }
            //    return GetTrans(C1, eigs1, C2);
            //}

            public static void GetEnergies(AlignData data1, IList <Vector> coords2
                                           , out double pot_rmsd, out double pot_enrg, out double pot_enrg_full, out double pot_enrg_anisou
                                           , Pdb pdb2           = null
                                           , string pdb2outpath = null
                                           )
            {
                Anisou[]      anisous1     = data1.GetAnisous();
                Trans3        trans        = GetTrans(data1.coords, anisous1, coords2);
                List <Vector> coords2trans = new List <Vector>(trans.GetTransformed(coords2));

                if (pdb2 != null && pdb2outpath != null)
                {
                    pdb2.ToFile(pdb2outpath, coords2trans);
                }
                //data1.pdb.ToFile(pdb2outpath, coords2trans, anisous: anisous1.GetUs());

                pot_rmsd        = data1.GetRmsdFrom(coords2trans);
                pot_enrg        = data1.GetEnergyFromDiag(coords2trans);
                pot_enrg_full   = data1.GetEnergyFromFull(coords2trans);
                pot_enrg_anisou = data1.GetEnergyFromAnisou(coords2trans);
            }
示例#28
0
        public static void ToFileAnimated(string filepath
                                          , IList <Atom> atoms
                                          , IList <Vector> velocities
                                          , IList <double> stepTimes = null
                                          , IList <Vector> coords    = null
                                          , IList <double> bfactors  = null
                                          , IList <Element> headers  = null
                                          , int?modelidx             = null
                                          )
        {
            if (coords == null)
            {
                coords = atoms.ListCoord();
            }
            if (stepTimes == null)
            {
                stepTimes = new double[] { 0.0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1.0,
                                           -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0,
                                           0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
                                           1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0, }
            }
            ;

            bool append = false;

            for (int i = 0; i < stepTimes.Count; i++)
            {
                List <Vector> lcoords  = coords.PwAdd(velocities, stepTimes[i]);
                List <string> lheaders = null;
                if ((append == false) && (headers != null))
                {
                    lheaders = headers.ToLines();
                }
                Pdb.ToFile(filepath, atoms, coords: lcoords, append: append, headers: lheaders, bfactors: bfactors
                           , modelidx: modelidx
                           );
                append = true;
            }
        }
    }
示例#29
0
        public static void FromFile(string filepath, out Pdb[] pdbs)
        {
            string[]  lines    = System.IO.File.ReadAllLines(filepath);
            Element[] elements = new Element[lines.Length];
            for (int i = 0; i < lines.Length; i++)
            {
                elements[i] = new Element(lines[i]);
            }

            elements = elements.UpdateElement();

            List <List <Element> > ensembles;

            {
                ensembles = new List <List <Element> >();
                ensembles.Add(new List <Element>());
                for (int i = 0; i < elements.Length; i++)
                {
                    //ensembles.Last().Add(elements[i]);
                    if (Atom.IsAtom(elements[i].line))
                    {
                        ensembles.Last().Add(elements[i]);
                    }
                    if (Endmdl.IsEndmdl(elements[i].line))
                    {
                        ensembles.Add(new List <Element>());
                    }
                }
                if (ensembles.Last().Count == 0)
                {
                    ensembles.Remove(ensembles.Last());
                }
            }

            pdbs = new Pdb[ensembles.Count];
            for (int i = 0; i < ensembles.Count; i++)
            {
                pdbs[i] = new Pdb(ensembles[i].ToArray());
            }
        }
示例#30
0
            public static Top FromPdb(string pdbpath
                                      , string ff    = "charmm27"
                                      , string water = "none"
                                      , HPack <Pdb> optout_confout = null
                                      )
            {
                Top top;

                FileInfo      pdbinfo  = new FileInfo(pdbpath);
                string        currdir  = HEnvironment.CurrentDirectory;
                DirectoryInfo temproot = HDirectory.CreateTempDirectory();

                HEnvironment.CurrentDirectory = temproot.FullName;
                {
                    HFile.Copy(pdbinfo.FullName, "protein.pdb");

                    RunPdb2gmx(f: "protein.pdb"
                               , o: "confout.pdb"
                               , p: "topol.top"
                               , q: "clean.pdb"
                               , ff: ff
                               , water: water
                               , merge: "all"
                               , lineStderr: null
                               , lineStdout: null
                               );

                    top = Top.FromFile("topol.top");
                    if (optout_confout != null)
                    {
                        optout_confout.value = Pdb.FromFile("confout.pdb");
                    }
                }
                HEnvironment.CurrentDirectory = currdir;
                Thread.Sleep(100);
                try{ temproot.Delete(true); } catch (Exception) {}

                return(top);
            }