コード例 #1
0
ファイル: ReadFiles.cs プロジェクト: sams28/Dock-Hap
        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;
        }
コード例 #2
0
ファイル: ReadFiles.cs プロジェクト: sams28/Dock-Hap
        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;
        }
コード例 #3
0
ファイル: Molecule.cs プロジェクト: sams28/Dock-Hap
 public Residue(Residue r,Chain c)
     : base(r)
 {
     number = r.number;
     atoms = new List<Atom>();
     resName =r.resName;
     resID = r.resID;
     resChain = c;
 }
コード例 #4
0
ファイル: Molecule.cs プロジェクト: sams28/Dock-Hap
        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;
        }
コード例 #5
0
ファイル: Molecule.cs プロジェクト: sams28/Dock-Hap
        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;
        }
コード例 #6
0
ファイル: Molecule.cs プロジェクト: sams28/Dock-Hap
        public Atom(string name,float charge,int num,Residue r,Chain c)
            : base()
        {
            number = num;
            atomFullName = name;
            atomName = name [0].ToString();
            atomCharge = charge;
            bonds = new List<int> ();

            int i =0;

            while((atomName != tableName[i]) && (i < tableName.Length)){

                i++;

            }

            atomMass = tableMass [i];
            atomRadius = tableRadius [i];

            atomResidue = r;
            atomChain = c;
        }
コード例 #7
0
ファイル: SelectAtoms.cs プロジェクト: sams28/Dock-Hap
    public void SetClosestElements(Molecule m,GameObject d)
    {
        int index;
        for (index =0; index < m.Atoms.Count; index++) {

            if (m.Atoms [index].Active)
                break;
        }
        minDistChain = m.Atoms [index].AtomChain;
        minDistResidue = m.Atoms[index].AtomResidue;
        minDistAtom = m.Atoms [index];
        float minDist = Vector3.Distance(minDistAtom.Location[Main.current_frame],d.transform.position);
        float dist;

        //Future implementation ?
        /*
        Ray ray = new Ray (o.transform.position, o.transform.forward);
        RaycastHit rHit;

        if (Physics.Raycast(ray, out rHit)) {

            minDistAtom.atom =  rHit.collider.gameObject;

        }

        */

        for (int i =index+1; i < m.Atoms.Count; i++) {

            if(m.Atoms[i].Active){
                dist =  Vector3.Distance(m.Atoms[i].Location[Main.current_frame],d.transform.position);

                if(dist < minDist){
                    minDist = dist;
                    minDistAtom = m.Atoms[i];
                    minDistResidue = m.Atoms[i].AtomResidue;
                    minDistChain =m.Atoms[i].AtomChain;

                }

            }
        }
    }