Beispiel #1
0
 public Pdb GetTransformed(Trans3 trans)
 {
     Element[] nelements = new Element[elements.Length];
     for (int i = 0; i < elements.Length; i++)
     {
         if (typeof(Atom).IsInstanceOfType(elements[i]))
         {
             Atom   atom = (Atom)elements[i];
             Vector pt   = atom.coord;
             pt           = trans.DoTransform(pt);
             atom         = Atom.FromString(atom.GetUpdatedLine(pt));
             nelements[i] = atom;
         }
         else if (typeof(Hetatm).IsInstanceOfType(elements[i]))
         {
             Hetatm hetatm = (Hetatm)elements[i];
             Vector pt     = hetatm.coord;
             pt           = trans.DoTransform(pt);
             hetatm       = Hetatm.FromString(hetatm.GetUpdatedLine(pt));
             nelements[i] = hetatm;
         }
         else
         {
             nelements[i] = elements[i].UpdateElement();
         }
     }
     return(new Pdb(nelements));
 }
Beispiel #2
0
            public static Atom FromHetatm(Hetatm hetatm)
            {
                string header = hetatm.line.Substring(0, 6);
                string data   = hetatm.line.Substring(6);

                HDebug.Assert(header.ToUpper() == Hetatm.RecordName.ToUpper());
                HDebug.Assert(header + data == hetatm.line);

                string atom_line = Atom.RecordName + data;
                Atom   atom      = Atom.FromString(atom_line);

                return(atom);
            }
Beispiel #3
0
        public static List <Tuple <Hetatm, int> > UpdateHetatms(Element[] elements)
        {
            int[] collection = Collect(elements, Hetatm.RecordName);
            List <Tuple <Hetatm, int> > hetatms = new List <Tuple <Hetatm, int> >();

            foreach (int idx in collection)
            {
                string line   = elements[idx].line;
                Hetatm hetatm = Hetatm.FromString(line);
                elements[idx] = hetatm;
                hetatms.Add(new Tuple <Hetatm, int>(hetatm, idx));
            }
            return(hetatms);
        }
Beispiel #4
0
            public static Hetatm FromData(int serial, string name, string resName, char chainID, int resSeq, double x, double y, double z, char?altLoc = null, char?iCode = null, double?occupancy = null, double?tempFactor = null, string element = null, string charge = null, string segment = null)
            {
                Hetatm hetatm = Hetatm.FromString(LineFromData(RecordName, serial, name, resName, chainID, resSeq, x, y, z
                                                               , altLoc: altLoc
                                                               , iCode: iCode
                                                               , occupancy: occupancy
                                                               , tempFactor: tempFactor
                                                               , element: element
                                                               , charge: charge
                                                               , segment: segment
                                                               ));

                return(hetatm);
            }
Beispiel #5
0
 public Pdb CloneUpdateCoord(Dictionary <IAtom, Vector> iatom2coord)
 {
     Element[] newelements = new Element[elements.Length];
     for (int i = 0; i < elements.Length; i++)
     {
         Element elem = elements[i];
         if (elem is IAtom)
         {
             if (iatom2coord.ContainsKey(elem as IAtom))
             {
                 Vector  coord = iatom2coord[elem as IAtom];
                 Element nelem = null;
                 if (elem is Atom)
                 {
                     if (nelem != null)
                     {
                         throw new HException("(nelem != null)");
                     }
                     Atom atom = elem as Atom;
                     nelem = Atom.FromString(atom.GetUpdatedLine(coord));
                 }
                 if (elem is Hetatm)
                 {
                     if (nelem != null)
                     {
                         throw new HException("(nelem != null)");
                     }
                     Hetatm hetatm = elem as Hetatm;
                     nelem = Hetatm.FromString(hetatm.GetUpdatedLine(coord));
                 }
                 if (nelem == null)
                 {
                     throw new NotImplementedException();
                 }
                 elem = nelem;
             }
         }
         newelements[i] = elem.UpdateElement();
     }
     return(new Pdb(newelements));
 }
Beispiel #6
0
        public Pdb CloneReplaceChainID(string IDfrom, string IDto)
        {
            if (IDfrom == null)
            {
                throw new ArgumentException("IDfrom is null");
            }
            if (IDto == null)
            {
                throw new ArgumentException("IDto is null");
            }
            if (IDfrom.Length != IDto.Length)
            {
                throw new ArgumentException("IDFrom.leng != IDto.leng");
            }

            Dictionary <char, char> from2to = GetPairChainID(IDfrom, IDto);

            if (from2to.ContainsKey('_'))
            {
                throw new ArgumentException("wildkey('_') is not allowed in IDfrom");
            }

            Element[] newelements = new Element[elements.Length];
            for (int i = 0; i < elements.Length; i++)
            {
                Element elem = elements[i];
                char?   ch   = null;
                if (elem is Atom)
                {
                    HDebug.Assert(ch == null); ch = (elem as Atom).chainID;
                }
                if (elem is Hetatm)
                {
                    HDebug.Assert(ch == null); ch = (elem as Hetatm).chainID;
                }
                if (elem is Anisou)
                {
                    HDebug.Assert(ch == null); ch = (elem as Anisou).chainID;
                }

                if (ch != null)
                {
                    if (from2to.ContainsKey(ch.Value))
                    {
                        if (from2to[ch.Value] == '_')
                        {
                            // if wildcard ('_') is in IDto, delete that atom
                            continue;
                        }
                        Element nelem = null;
                        if (elem is Atom)
                        {
                            if (nelem != null)
                            {
                                throw new HException("(nelem != null)");
                            }
                            Atom atom = elem as Atom;
                            nelem = Atom.FromData(
                                serial: atom.serial,
                                name: atom.name,
                                resName: atom.resName,
                                chainID: from2to[atom.chainID],
                                resSeq: atom.resSeq,
                                x: atom.x,
                                y: atom.y,
                                z: atom.z,
                                altLoc: atom.altLoc,
                                iCode: atom.iCode,
                                occupancy: atom.occupancy,
                                tempFactor: atom.tempFactor,
                                element: atom.element,
                                charge: atom.charge
                                );
                        }
                        if (elem is Hetatm)
                        {
                            if (nelem != null)
                            {
                                throw new HException("(nelem != null)");
                            }
                            Hetatm hetatm = elem as Hetatm;
                            nelem = Hetatm.FromData(
                                serial: hetatm.serial,
                                name: hetatm.name,
                                resName: hetatm.resName,
                                chainID: from2to[hetatm.chainID],
                                resSeq: hetatm.resSeq,
                                x: hetatm.x,
                                y: hetatm.y,
                                z: hetatm.z,
                                altLoc: hetatm.altLoc,
                                iCode: hetatm.iCode,
                                occupancy: hetatm.occupancy,
                                tempFactor: hetatm.tempFactor,
                                element: hetatm.element,
                                charge: hetatm.charge
                                );
                        }
                        if (elem is Anisou)
                        {
                            if (nelem != null)
                            {
                                throw new HException("(nelem != null)");
                            }
                            Anisou anisou = elem as Anisou;
                            nelem = Anisou.FromData(anisou.line
                                                    , chainID: from2to[anisou.chainID]
                                                    );
                        }
                        if (nelem == null)
                        {
                            throw new NotImplementedException();
                        }
                        elem = nelem;
                    }
                }
                newelements[i] = elem.UpdateElement();
            }
            newelements = newelements.HRemoveAll(null);

            return(new Pdb(newelements));
        }
Beispiel #7
0
            public static Element UpdateElement(string line)
            {
                line = (line + "                                                                                ").Substring(0, 80);
                if (Header.IsHeader(line))
                {
                    return(Header.FromString(line));                        // Title Section
                }
                if (Title.IsTitle(line))
                {
                    return(Title.FromString(line));                         // Title Section
                }
                if (Compnd.IsCompnd(line))
                {
                    return(Compnd.FromString(line));                        // Title Section
                }
                if (Source.IsSource(line))
                {
                    return(Source.FromString(line));                        // Title Section
                }
                if (Keywds.IsKeywds(line))
                {
                    return(Keywds.FromString(line));                        // Title Section
                }
                if (Expdta.IsExpdta(line))
                {
                    return(Expdta.FromString(line));                        // Title Section
                }
                if (Nummdl.IsNummdl(line))
                {
                    return(Nummdl.FromString(line));                        // Title Section
                }
                if (Author.IsAuthor(line))
                {
                    return(Author.FromString(line));                        // Title Section
                }
                if (Revdat.IsRevdat(line))
                {
                    return(Revdat.FromString(line));                        // Title Section
                }
                if (Jrnl.IsJrnl(line))
                {
                    return(Jrnl.FromString(line));                          // Title Section
                }
                if (Remark.IsRemark(line))
                {
                    return(Remark.FromString(line));                        // Title Section
                }
                if (Seqres.IsSeqres(line))
                {
                    return(Seqres.FromString(line));                        // Primary Structure Section
                }
                if (Seqadv.IsSeqadv(line))
                {
                    return(Seqadv.FromString(line));                        // Primary Structure Section
                }
                if (Helix.IsHelix(line))
                {
                    return(Helix.FromString(line));                         // Secondary Structure Section
                }
                if (Sheet.IsSheet(line))
                {
                    return(Sheet.FromString(line));                         // Secondary Structure Section
                }
                if (Site.IsSite(line))
                {
                    return(Site.FromString(line));                          // Miscellaneous Features Section
                }
                if (Cryst1.IsCryst1(line))
                {
                    return(Cryst1.FromString(line));                        // Crystallographic and Coordinate Transformation Section
                }
                if (Anisou.IsAnisou(line))
                {
                    return(Anisou.FromString(line));                        // Coordinate Section
                }
                if (Atom.IsAtom(line))
                {
                    return(Atom.FromString(line));                          // Coordinate Section
                }
                if (Endmdl.IsEndmdl(line))
                {
                    return(Endmdl.FromString(line));                        // Coordinate Section
                }
                if (Hetatm.IsHetatm(line))
                {
                    return(Hetatm.FromString(line));                        // Coordinate Section
                }
                if (Model.IsModel(line))
                {
                    return(Model.FromString(line));                         // Coordinate Section
                }
                if (Siguij.IsSiguij(line))
                {
                    return(Siguij.FromString(line));                        // Coordinate Section
                }
                if (Ter.IsTer(line))
                {
                    return(Ter.FromString(line));                           // Coordinate Section
                }
                if (Conect.IsConect(line))
                {
                    return(Conect.FromString(line));                        // Connectivity Section
                }
                if (Master.IsMaster(line))
                {
                    return(Master.FromString(line));                        // Bookkeeping Section
                }
                if (End.IsEnd(line))
                {
                    return(End.FromString(line));                           // Bookkeeping Section
                }
                if (line.Substring(0, 6) == "DBREF ")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SEQRES")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "MODRES")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "HET   ")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "HETNAM")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "FORMUL")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SSBOND")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "LINK  ")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "ORIGX1")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "ORIGX2")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "ORIGX3")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SCALE1")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SCALE2")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SCALE3")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "CISPEP")
                {
                    return(new Element(line));                                  // Connectivity Annotation Section
                }
                if (line.Substring(0, 6) == "HETSYN")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SEQADV")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SPRSDE")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "MTRIX1")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "MTRIX2")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "MTRIX3")
                {
                    return(new Element(line));
                }

                if (line.Substring(0, 6) == "MDLTYP")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SPLIT ")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "CAVEAT")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "OBSLTE")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "HYDBND")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SLTBRG")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "TVECT ")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "DBREF1")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "DBREF2")
                {
                    return(new Element(line));
                }
                if (line.Substring(0, 6) == "SIGATM")
                {
                    return(new Element(line));
                }

                HDebug.Assert(false);
                return(new Element(line));
            }