/// <summary>Atom模式选取</summary>
    public void SetData(AtomDisplayer atomDisplayer)
    {
        AtomInAminoacid    atomInAminoacid    = atomDisplayer.AtomInAminoacid;
        AminoacidInProtein aminoacidInProtein = atomDisplayer.AminoacidInProtein;
        Chain   chain   = aminoacidInProtein.Chain;
        Protein protein = chain.Protein;

        SetProteinData(protein);
        SetChainData(chain);
        SetAminoacidData(aminoacidInProtein);
        SetAtomData(aminoacidInProtein, atomInAminoacid);
    }
Beispiel #2
0
    public void SetBoardInfo(AtomDisplayer atomDisplayer)
    {
        if (atomDisplayer == null)
        {
            proteinInfoText.text   = "";
            chaininInfoText.text   = "";
            aminoacidInfoText.text = "";
            atomInfoText.text      = "";
            return;
        }
        AtomInAminoacid    atomInAminoacid    = atomDisplayer.AtomInAminoacid;
        AminoacidInProtein aminoacidInProtein = atomDisplayer.AminoacidInProtein;
        Chain   chain   = aminoacidInProtein.Chain;
        Protein protein = chain.Protein;

        proteinInfoText.text = string.Format("-Protein-\nID: {0}\nClassification: {1}\nPublishDate: {2}",
                                             protein.ID, protein.Classification, protein.PublishDate);
        chaininInfoText.text = string.Format("-Chain-\nID: {0}\nOXT: {1}",
                                             chain.ID, chain.OXT != null);
        aminoacidInfoText.text = string.Format("-Aminoacid-\nSeq: {0}\nType: {1}\nIsStandard: {2}",
                                               aminoacidInProtein.ResidueSeq, aminoacidInProtein.Aminoacid.Type.ToString(), aminoacidInProtein.Aminoacid.IsStandard);
        atomInfoText.text = string.Format("-Atom-\nName: {0}\nSerial: {1}\nPosition: {2}",
                                          atomInAminoacid.Name, aminoacidInProtein.AtomInAminoacidSerial[atomInAminoacid], aminoacidInProtein.AtomInAminoacidPos[atomInAminoacid].ToString("F3"));
    }
Beispiel #3
0
 public ShowInfoInBoardCommand(AtomDisplayer atomDisplayer)
 {
     this.AtomDisplayer = atomDisplayer;
 }
Beispiel #4
0
 public void SetBoardInfo(AtomDisplayer atomDisplayer)
 {
     polymerInfoDisplayer.SetData(atomDisplayer);
 }
Beispiel #5
0
    /// <summary>根据DisplayMode创建整个蛋白质模型 </summary>
    public void CreateProtein(Protein protein, DisplayMode displayMode)
    {
        Vector3 initPos = Vector3.zero;

        //若之前已创建Protein 则继承原来的位置 否则在摄像机的前2米初始化
        if (proteinDisplayerGo != null)
        {
            initPos = proteinDisplayerGo.transform.position;
        }
        else
        {
            Camera mainCamera = Camera.main;
            initPos = mainCamera.transform.position + oriOffsetToMainCamera.z * mainCamera.transform.forward
                      + oriOffsetToMainCamera.y * mainCamera.transform.up + oriOffsetToMainCamera.x * mainCamera.transform.right;
        }

        proteinDisplayerGo      = Instantiate(proteinTemplatePrefeb, Displayer3DRoot.transform, true);
        proteinDisplayerGo.name = protein.ID;
        proteinDisplayerGo.GetComponent <ProteinDisplayer>().Protein = protein;
        foreach (var chainKvp in protein.Chains)
        {
            Chain      chain            = chainKvp.Value;
            GameObject chainDisplayerGo = new GameObject(chain.ID, typeof(ChainDisplayer));
            chainDisplayerGo.GetComponent <ChainDisplayer>().Chain = chain;
            chainDisplayerGo.transform.SetParent(proteinDisplayerGo.transform);
            //创建每个原子模型
            foreach (var aminoacidKvp in chain.SeqAminoacids)
            {
                AminoacidInProtein aminoacidInProtein = aminoacidKvp.Value;
                //GameObject aminoacidDisplayerGo = new GameObject(aminoacidInProtein.ResidueSeq.ToString(), typeof(AminoacidDisplayer));
                GameObject aminoacidDisplayerGo = Instantiate <GameObject>(residueTemplatePrefeb, chainDisplayerGo.transform);
                aminoacidDisplayerGo.name = aminoacidInProtein.ResidueSeq.ToString();
                AminoacidDisplayer aminoacidDisplayer = aminoacidDisplayerGo.GetComponent <AminoacidDisplayer>();
                aminoacidDisplayer.AminoacidInProtein = aminoacidInProtein;

                //棍状模型不显示原子球
                if (displayMode != DisplayMode.Sticks)
                {
                    foreach (var atomKvp in aminoacidInProtein.AtomInAminoacidSerial)
                    {
                        AtomInAminoacid atomInAminoacid       = atomKvp.Key;
                        GameObject      atomDisplayerGoPrefeb = GetAtomPrefeb(atomInAminoacid.Aminoacid.Type);
                        switch (displayMode)
                        {
                        case DisplayMode.Spacefill: atomDisplayerGoPrefeb.transform.localScale = new Vector3(AtomFillSize, AtomFillSize, AtomFillSize); break;

                        case DisplayMode.BallStick: atomDisplayerGoPrefeb.transform.localScale = new Vector3(AtomBallStickSize, AtomBallStickSize, AtomBallStickSize); break;

                        default: throw new System.Exception(string.Format("Unhandled displayMode: {0}", displayMode));
                        }
                        GameObject atomDisplayerGo = Instantiate(atomDisplayerGoPrefeb, aminoacidDisplayerGo.transform, false);
                        atomDisplayerGo.name = atomInAminoacid.Name;
                        atomDisplayerGo.transform.localPosition = (aminoacidInProtein.AtomInAminoacidPos[atomInAminoacid] - protein.CenterPos) * BallStickPosScale;
                        AtomDisplayer atomDisplayer = atomDisplayerGo.GetComponent <AtomDisplayer>();
                        atomDisplayer.AtomInAminoacid    = atomInAminoacid;
                        atomDisplayer.AminoacidInProtein = aminoacidInProtein;
                    }
                }
                //创建每个键的模型
                if (displayMode == DisplayMode.BallStick || displayMode == DisplayMode.Sticks)
                {
                    AminoacidInProtein lastAminoacidInProtein = null;
                    //若在该链存在上一序列号的残基 则构造一个该残基的N连通上一残基的C形成的肽键
                    if (aminoacidInProtein.Chain.SeqAminoacids.TryGetValue(aminoacidInProtein.ResidueSeq - 1, out lastAminoacidInProtein))
                    {
                        //两个Bond 两个颜色
                        string        name1          = string.Format("{0}-{1}-Peptidebond", lastAminoacidInProtein.ResidueSeq, aminoacidInProtein.ResidueSeq);
                        string        name2          = string.Format("{0}-{1}-Peptidebond", aminoacidInProtein.ResidueSeq, lastAminoacidInProtein.ResidueSeq);
                        Vector3       pos1           = (lastAminoacidInProtein.AtomInAminoacidPos[lastAminoacidInProtein.Aminoacid["C"]] - protein.CenterPos) * BallStickPosScale;
                        Vector3       pos3           = (aminoacidInProtein.AtomInAminoacidPos[aminoacidInProtein.Aminoacid["N"]] - protein.CenterPos) * BallStickPosScale;
                        Vector3       pos2           = (pos1 + pos3) / 2;
                        BondType      bondType       = BondType.Single;
                        Transform     parent         = aminoacidDisplayerGo.transform;
                        AminoacidType aminoacidType1 = lastAminoacidInProtein.Aminoacid.Type;
                        AminoacidType aminoacidType2 = aminoacidInProtein.Aminoacid.Type;
                        GenerateBondGameObject(name1, pos1, pos2, bondType, parent, aminoacidType1, displayMode);
                        GenerateBondGameObject(name2, pos2, pos3, bondType, parent, aminoacidType2, displayMode);
                    }
                    //氨基酸内的化学键(从本地Aminoacid数据中获取的连接关系)
                    foreach (var connection in aminoacidInProtein.Aminoacid.Connections)
                    {
                        string  name = string.Format("{0}-{1}-bond", connection.Key.Key.Name, connection.Key.Value.Name);
                        Vector3 pos1 = Vector3.zero; Vector3 pos2 = Vector3.zero;
                        //若读取的pdb文件中的某残基中没有连接关系中的某个原子 说明源pdb文件出现数据遗漏
                        try {
                            pos1 = (aminoacidInProtein.AtomInAminoacidPos[connection.Key.Key] - protein.CenterPos) * BallStickPosScale;
                            pos2 = (aminoacidInProtein.AtomInAminoacidPos[connection.Key.Value] - protein.CenterPos) * BallStickPosScale;
                        }
                        catch (KeyNotFoundException ex) {
                            //Debug.LogWarning(string.Format("The aminoacidInProtein: {0} is not complete, the atom in connection: {1}-{2} is losed", aminoacidInProtein, connection.Key.Key.Name, connection.Key.Value.Name));
                            continue;
                        }
                        BondType      bondType      = connection.Value;
                        Transform     parent        = aminoacidDisplayerGo.transform;
                        AminoacidType aminoacidType = aminoacidInProtein.Aminoacid.Type;
                        GenerateBondGameObject(name, pos1, pos2, bondType, parent, aminoacidType, displayMode);
                    }
                }
                //若合并Mesh 在Residue的mesh合并渲染 所有子物体不渲染
                if (conbineMesh)
                {
                    MeshFilter   residueMeshFilter   = aminoacidDisplayerGo.AddComponent <MeshFilter>();
                    MeshRenderer residueMeshRenderer = aminoacidDisplayerGo.AddComponent <MeshRenderer>();
                    residueMeshFilter.sharedMesh       = aminoacidDisplayerGo.transform.CombineChildsMesh();
                    residueMeshRenderer.sharedMaterial = GetMaterial(aminoacidInProtein.Aminoacid.Type);
                    MeshRenderer[] childMeshRenderers = aminoacidDisplayerGo.GetComponentsInChildren <MeshRenderer>();
                    foreach (var renderer in childMeshRenderers)
                    {
                        renderer.enabled = false;
                    }
                    residueMeshRenderer.enabled  = true;
                    aminoacidDisplayer.Normal    = GetMaterial(aminoacidInProtein.Aminoacid.Type);
                    aminoacidDisplayer.HighLight = GetHighlightMaterial(aminoacidInProtein.Aminoacid.Type);
                }
            }
        }
        proteinDisplayerGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); //缩放0.2倍
        proteinDisplayerGo.transform.position   = initPos;
    }
Beispiel #6
0
    public void ShowProtein(Protein protein)
    {
        GameObject proteinDisplayerGo = new GameObject(protein.ID, typeof(ProteinDisplayer));

        proteinDisplayerGo.GetComponent <ProteinDisplayer>().Protein = protein;

        Displayer3DRoot.transform.localPosition = Vector3.zero;
        Displayer3DRoot.transform.localRotation = Quaternion.identity;
        Displayer3DRoot.transform.localScale    = new Vector3(1, 1, 1);
        proteinDisplayerGo.transform.SetParent(Displayer3DRoot.transform);

        foreach (var chainKvp in protein.Chains)
        {
            Chain      chain            = chainKvp.Value;
            GameObject chainDisplayerGo = new GameObject(chain.ID, typeof(ChainDisplayer));
            chainDisplayerGo.GetComponent <ChainDisplayer>().Chain = chain;
            chainDisplayerGo.transform.SetParent(proteinDisplayerGo.transform);
            //创建每个原子模型
            foreach (var aminoacidKvp in chain.SeqAminoacids)
            {
                AminoacidInProtein aminoacidInProtein   = aminoacidKvp.Value;
                GameObject         aminoacidDisplayerGo = new GameObject(aminoacidInProtein.ResidueSeq.ToString(), typeof(AminoacidDisplayer));
                aminoacidDisplayerGo.GetComponent <AminoacidDisplayer>().AminoacidInProtein = aminoacidInProtein;
                aminoacidDisplayerGo.transform.SetParent(chainDisplayerGo.transform);
                foreach (var atomKvp in aminoacidInProtein.AtomInAminoacidSerial)
                {
                    AtomInAminoacid atomInAminoacid       = atomKvp.Key;
                    GameObject      atomDisplayerGoPrefeb = GetAtomPrefeb(atomInAminoacid.Aminoacid.Type);
                    switch (displayMode)
                    {
                    case DisplayMode.Spacefill: atomDisplayerGoPrefeb.transform.localScale = new Vector3(AtomFillSize, AtomFillSize, AtomFillSize); break;

                    case DisplayMode.BallStick: atomDisplayerGoPrefeb.transform.localScale = new Vector3(AtomBallStickSize, AtomBallStickSize, AtomBallStickSize); break;

                    case DisplayMode.Stick: atomDisplayerGoPrefeb.transform.localScale = new Vector3(AtomStickSize, AtomStickSize, AtomStickSize); break;

                    default: throw new System.Exception(string.Format("Unhandled displayMode: {0}", displayMode));
                    }
                    GameObject atomDisplayerGo = Instantiate(atomDisplayerGoPrefeb, aminoacidDisplayerGo.transform, false);
                    atomDisplayerGo.name = atomInAminoacid.Name;
                    atomDisplayerGo.transform.localPosition = (aminoacidInProtein.AtomInAminoacidPos[atomInAminoacid] - protein.CenterPos) * BallStickPosScale;
                    AtomDisplayer atomDisplayer = atomDisplayerGo.GetComponent <AtomDisplayer>();
                    atomDisplayer.AtomInAminoacid    = atomInAminoacid;
                    atomDisplayer.AminoacidInProtein = aminoacidInProtein;
                }
                //创建每个键的模型
                if (displayMode == DisplayMode.BallStick || displayMode == DisplayMode.Stick)
                {
                    AminoacidInProtein lastAminoacidInProtein = null;
                    //若在该链存在上一序列号的残基 则构造一个该残基的N连通上一残基的C形成的肽键
                    if (aminoacidInProtein.Chain.SeqAminoacids.TryGetValue(aminoacidInProtein.ResidueSeq - 1, out lastAminoacidInProtein))
                    {
                        //两个Bond 两个颜色
                        string        name1          = string.Format("{0}-{1}-Peptidebond", lastAminoacidInProtein.ResidueSeq, aminoacidInProtein.ResidueSeq);
                        string        name2          = string.Format("{0}-{1}-Peptidebond", aminoacidInProtein.ResidueSeq, lastAminoacidInProtein.ResidueSeq);
                        Vector3       pos1           = (lastAminoacidInProtein.AtomInAminoacidPos[lastAminoacidInProtein.Aminoacid["C"]] - protein.CenterPos) * BallStickPosScale;
                        Vector3       pos3           = (aminoacidInProtein.AtomInAminoacidPos[aminoacidInProtein.Aminoacid["N"]] - protein.CenterPos) * BallStickPosScale;
                        Vector3       pos2           = (pos1 + pos3) / 2;
                        BondType      bondType       = BondType.Single;
                        Transform     parent         = aminoacidDisplayerGo.transform;
                        AminoacidType aminoacidType1 = lastAminoacidInProtein.Aminoacid.Type;
                        AminoacidType aminoacidType2 = aminoacidInProtein.Aminoacid.Type;
                        GenerateBondGameObject(name1, pos1, pos2, bondType, parent, aminoacidType1);
                        GenerateBondGameObject(name2, pos2, pos3, bondType, parent, aminoacidType2);
                    }
                    //氨基酸内的化学键(从本地Aminoacid数据中获取的连接关系)
                    foreach (var connection in aminoacidInProtein.Aminoacid.Connections)
                    {
                        string  name = string.Format("{0}-{1}-bond", connection.Key.Key.Name, connection.Key.Value.Name);
                        Vector3 pos1 = Vector3.zero; Vector3 pos2 = Vector3.zero;
                        //若读取的pdb文件中的某残基中没有连接关系中的某个原子 说明源pdb文件出现数据遗漏
                        try
                        {
                            pos1 = (aminoacidInProtein.AtomInAminoacidPos[connection.Key.Key] - protein.CenterPos) * BallStickPosScale;
                            pos2 = (aminoacidInProtein.AtomInAminoacidPos[connection.Key.Value] - protein.CenterPos) * BallStickPosScale;
                        }
                        catch (KeyNotFoundException)
                        {
                            //Debug.LogWarning(string.Format("The aminoacidInProtein: {0} is not complete, the atom in connection: {1}-{2} is losed", aminoacidInProtein, connection.Key.Key.Name, connection.Key.Value.Name));
                            continue;
                        }
                        BondType      bondType      = connection.Value;
                        Transform     parent        = aminoacidDisplayerGo.transform;
                        AminoacidType aminoacidType = aminoacidInProtein.Aminoacid.Type;
                        GenerateBondGameObject(name, pos1, pos2, bondType, parent, aminoacidType);
                    }
                }
            }
        }
    }
    //public void OnBallStickToggleChanged(bool value)
    //{
    //    ProteinDisplayModel model = GetModel<ProteinDisplayModel>();
    //    ProteinDisplayView view = GetView<ProteinDisplayView>();
    //    Protein protein = model.DisplayedProteinData;
    //    view.displayMode = value ? DisplayMode.BallStick : DisplayMode.Spacefill;
    //    DestroyProtein();
    //    view.ShowProtein(protein);
    //}

    public void ShowInfoInBoard(AtomDisplayer atomDisplayer)
    {
        ProteinDisplayView view = GetView <ProteinDisplayView>();

        view.SetBoardInfo(atomDisplayer);
    }