Пример #1
0
        public static Molecule ReadGRO(TextReader sr)
        {
            lastresID =-1;
            lastchainID = "NONE";
            nowresidue = -1;
            nowchain = 0;

            nbatom=0;
            nbresidue=0;
            Molecule mol = new Molecule ();
            Residue r =new Residue();
            chainID = "None";
            mol.Chains.Add(new Chain("ATOM",chainID));
            mol.Chains.Add(new Chain("HETATM",chainID));
            //We skip the first two lines
            sr.ReadLine ();
            sr.ReadLine ();

            while ((s=sr.ReadLine())!=null) {

                if(s.Length>50) {

                    resID = int.Parse(s.Substring(0,5));

                    if((lastresID != resID)){
                        resname = s.Substring(5,5).Trim();

                        if(resname != "SOL" &&resname != "DLC" &&resname != "WAT" && resname != "HOH"){
                            r =new Residue(resname,nbresidue,resID,mol.Chains[0]);
                            /*everything after dlc is a hetatm
                            if(nowchain != 0){
                                nowresidue = -1;
                            }
                            nowchain =0;
                            */
                            mol.Chains[nowchain].Residues.Add(r);
                            mol.Residues.Add(r);
                            nbresidue++;

                        }
                        else{
                            r =new Residue(resname,nbresidue,resID,mol.Chains[1]);
                            if(nowchain != 1){
                                nowresidue = -1;
                            }
                            nowchain =1;
                            mol.Chains[nowchain].Residues.Add(r);
                            mol.Residues.Add(r);
                            nbresidue++;
                        }

                        nowresidue++;
                        lastresID = resID;

                    }

                    atomname = s.Substring(10,5).Trim ();

                    if(resname != "SOL" &&resname != "DLC" &&resname != "WAT" ){
                    Atom at =new Atom(atomname,0.0f,nbatom,r,mol.Chains[0]);
                        mol.Chains[nowchain].Residues[nowresidue].Atoms.Add(at);
                        mol.Chains[nowchain].Atoms.Add(at);
                        mol.Atoms.Add(at);
                    }
                    else{
                        Atom at =new Atom(atomname,0.0f,nbatom,r,mol.Chains[1]);
                        mol.Chains[nowchain].Residues[nowresidue].Atoms.Add(at);
                        mol.Chains[nowchain].Atoms.Add(at);
                        mol.Atoms.Add(at);
                    }

                    //Unity has a left-handed coordinates system while PDBs are right-handed
                    //So we have to reverse the X coordinates
                    x = -float.Parse (s.Substring(20,8),System.Globalization.CultureInfo.InvariantCulture);
                    y = float.Parse (s.Substring(28,8),System.Globalization.CultureInfo.InvariantCulture);
                    z = float.Parse (s.Substring(36,8),System.Globalization.CultureInfo.InvariantCulture);
                    //convert nanometers to Angstorms
                    x*=10;
                    y*=10;
                    z*=10;
                    vect = new Vector3(x,y,z);

                    mol.Atoms[nbatom].Location[0] = vect;

                    nbatom++;

                }

            }

            sr.Close ();
            Debug.Log ("atoms:" + mol.Atoms.Count);
            return mol;
        }
Пример #2
0
        public Molecule(Molecule m)
            : base(m)
        {
            chains = new List<Chain> ();
            residues = new List<Residue> ();
            atoms = new List<Atom> ();

            for (int i = 0; i<m.Chains.Count; i++) {
                Chain c= new Chain(m.Chains[i]);
                this.Chains.Add(c);

                for (int j = 0; j<m.Chains[i].Residues.Count; j++) {
                    Residue r = new Residue(m.Chains[i].Residues[j],c);

                    this.Chains[i].Residues.Add(r);
                    this.Residues.Add(r);

                    for (int k =0; k<m.Chains[i].Residues[j].Atoms.Count; k++) {

                        Atom a = new Atom(m.Chains[i].Residues[j].Atoms[k],r,c);
                        this.Chains[i].Residues[j].Atoms.Add(a);
                        this.Chains[i].Atoms.Add(a);
                        this.Atoms.Add(a);

                    }

                }

            }

            bonds = new List<int[]> (m.Bonds);
            chainsBonds = new List<List<int>> (m.chainsBonds);

            color = m.color;
            type = m.type;
            render = m.render;
            select = m.select;
            energies = m.energies;
        }
Пример #3
0
        public static Molecule ReadPDB(TextReader sr)
        {
            Molecule mol = new Molecule ();
            bool mul_pos =false;
            Chain c = new Chain();
            Residue r = new Residue();
            lastresID =-1;
            lastchainID = "NONE";
            nowresidue = -1;
            nowchain = -1;
            nbatom = 0;
            nbresidue=0;

            while((s=sr.ReadLine())!=null) {

                if(s.StartsWith("ENDMDL") && !mul_pos){
                    break;
                }

                if(s.StartsWith("MODEL")){

                    mul_pos =true;
                    nbatom =0;
                    int frame = int.Parse(s.Substring(10,4));

                    if(frame > 1)
                    {
                        Main.total_frames++;
                    }

                }

                if(s.Length>4) {

                    if(s.StartsWith("ATOM") || s.StartsWith("HETATM")) {

                        if(Main.total_frames < 2){
                            chainID = s.Substring(21,1).Trim();

                            if(String.Compare(lastchainID,chainID) !=0){

                                if(s.StartsWith("ATOM"))
                                    c=new Chain("ATOM",chainID);
                                else
                                    c=new Chain("HETATM",chainID);
                                mol.Chains.Add(c);
                                nowchain++;
                                nowresidue =-1;

                                lastchainID = chainID;

                            }

                            resID = int.Parse(s.Substring(22,4));

                            if((lastresID != resID)){
                                resname=s.Substring(17,3).Trim();
                                r = new Residue(resname,nbresidue,resID,c);
                                mol.Chains[nowchain].Residues.Add(r);
                                mol.Residues.Add(r);
                                nowresidue++;
                                nbresidue++;
                                lastresID = resID;

                            }

                            atomname=s.Substring(12,4).Trim();
                            Atom at = new Atom(atomname,0.0f,nbatom,r,c);
                            mol.Chains[nowchain].Residues[nowresidue].Atoms.Add(at);
                            mol.Chains[nowchain].Atoms.Add(at);
                            mol.Atoms.Add(at);

                        }

                        //Unity has a left-handed coordinates system while PDBs are right-handed
                        //So we have to reverse the X coordinates
                        //InvariantCulture necessary form cross-platform
                        x=-float.Parse(s.Substring(30,8),System.Globalization.CultureInfo.InvariantCulture);
                        y=float.Parse(s.Substring(38,8),System.Globalization.CultureInfo.InvariantCulture);
                        z=float.Parse(s.Substring(46,8),System.Globalization.CultureInfo.InvariantCulture);
                        vect = new Vector3(x,y,z);
                        mol.Atoms[nbatom].Location[Main.total_frames-1] = vect;

                        nbatom++;

                    }

                }

            }

            sr.Close ();

            Debug.Log ("atoms:" + mol.Atoms.Count);
            return mol;
        }
Пример #4
0
        public Atom(Atom a,Residue r,Chain c)
            : base(a)
        {
            number = a.number;
            atomFullName = a.atomFullName;
            atomName = a.atomName;
            atomCharge = a.atomCharge;
            bonds = new List<int>(a.bonds);
            atomMass = a.atomMass;
            atomRadius = a.atomRadius;

            atomResidue = r;
            atomChain = c;
        }