Example #1
0
    public void AddMoleculeType(string pdbName, Color color)
    {
        var atoms = PdbReader.ReadPdbFile(Application.dataPath + "/Molecules/" + pdbName + ".pdb");

        _atomCount.Add(atoms.Count);
        _atomStart.Add(_atomDataPdb.Count);
        _atomDataPdb.AddRange(atoms);
        _molColors.Add(color);

        if (_molAtomCountBuffer == null)
        {
            _molAtomCountBuffer = new ComputeBuffer(1000, 4);
        }
        if (_molAtomStartBuffer == null)
        {
            _molAtomStartBuffer = new ComputeBuffer(1000, 4);
        }
        if (_atomDataPdbBuffer == null)
        {
            _atomDataPdbBuffer = new ComputeBuffer(1000000, 16);
        }
        if (_molColorsBuffer == null)
        {
            _molColorsBuffer = new ComputeBuffer(1000, 16);
        }

        _molAtomCountBuffer.SetData(_atomCount.ToArray());
        _molAtomStartBuffer.SetData(_atomStart.ToArray());
        _atomDataPdbBuffer.SetData(_atomDataPdb.ToArray());
        _molColorsBuffer.SetData(_molColors.ToArray());
    }
Example #2
0
    void ReloadScene()
    {
        Debug.Log("Reload scene: " + gameObject.name);

        GameObjects.Clear();
        _moleculeNames.Clear();
        _moleculeColors.Clear();

        foreach (var go in from Transform t in transform select t.gameObject)
        {
            var molecule = go.GetComponent <MoleculeScript>();
            var pdbName  = go.name.Split('_')[1];

            // Check if molecule already exists
            if (!HasMoleculeType(pdbName))
            {
                Debug.Log("Load molecule : " + pdbName);
                var atoms = PdbReader.ReadPdbFile(Application.dataPath + "/Molecules/" + pdbName + ".pdb");

                // Add new molecule type
                AddMoleculeType(pdbName, molecule.Color, atoms);
            }

            molecule.Type = GetMoleculeType(pdbName);
            GameObjects.Add(go);
        }
    }
    public void AddMolecule(string pdbName)
    {
        // Check if molecule already exists
        if (!HasMoleculeType(pdbName))
        {
            Debug.Log("Load molecule : " + pdbName);
            var atoms = PdbReader.ReadPdbFile(Application.dataPath + "/Molecules/" + pdbName + ".pdb");

            // Add new molecule type
            AddMoleculeType(pdbName, new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)), atoms);
        }

        this.AddMoleculeInstance(pdbName, new Vector3(Random.Range(-25, 25), Random.Range(-25, 25) + 25, Random.Range(-25, 25)) * 2, Random.rotation);
    }
Example #4
0
    private void CreateResources()
    {
        string pdbPath = Application.dataPath + "/Molecules/1.pdb";
        var    atoms   = PdbReader.ReadPdbFile(pdbPath);

        _atomBuffer = new ComputeBuffer(atoms.Count, sizeof(float) * 4, ComputeBufferType.Default);
        _atomBuffer.SetData(atoms.ToArray());

        _voxelBuffer = new ComputeBuffer(VolumeSize * VolumeSize * VolumeSize, sizeof(float), ComputeBufferType.Default);

        _volumeTexture                   = new RenderTexture(VolumeSize, VolumeSize, 0, RenderTextureFormat.RFloat);
        _volumeTexture.volumeDepth       = VolumeSize;
        _volumeTexture.isVolume          = true;
        _volumeTexture.enableRandomWrite = true;
        _volumeTexture.filterMode        = FilterMode.Trilinear;
        _volumeTexture.Create();
    }
    private void CreateResources()
    {
        _volumeTexture_1                   = new RenderTexture(VolumeSize, VolumeSize, 0, RenderTextureFormat.RFloat);
        _volumeTexture_1.volumeDepth       = VolumeSize;
        _volumeTexture_1.isVolume          = true;
        _volumeTexture_1.enableRandomWrite = true;
        _volumeTexture_1.filterMode        = FilterMode.Trilinear;
        _volumeTexture_1.wrapMode          = TextureWrapMode.Clamp;
        _volumeTexture_1.Create();

        _volumeTexture_2                   = new RenderTexture(VolumeSize, VolumeSize, 0, RenderTextureFormat.RFloat);
        _volumeTexture_2.volumeDepth       = VolumeSize;
        _volumeTexture_2.isVolume          = true;
        _volumeTexture_2.enableRandomWrite = true;
        _volumeTexture_2.filterMode        = FilterMode.Trilinear;
        _volumeTexture_2.wrapMode          = TextureWrapMode.Clamp;
        _volumeTexture_2.Create();

        _volumeTexture_3                   = new RenderTexture(VolumeSize, VolumeSize, 0, RenderTextureFormat.RFloat);
        _volumeTexture_3.volumeDepth       = VolumeSize;
        _volumeTexture_3.isVolume          = true;
        _volumeTexture_3.enableRandomWrite = true;
        _volumeTexture_3.filterMode        = FilterMode.Trilinear;
        _volumeTexture_3.wrapMode          = TextureWrapMode.Clamp;
        _volumeTexture_3.Create();

        //flatVolumeBuffer = new ComputeBuffer(VolumeSize * VolumeSize * VolumeSize, sizeof(float), ComputeBufferType.Default);

        string pdbPath = Application.dataPath + "/Molecules/" + "1.pdb";
        var    atoms   = PdbReader.ReadPdbFile(pdbPath);

        atomBuffer = new ComputeBuffer(atoms.Count, sizeof(float) * 4, ComputeBufferType.Default);
        atomBuffer.SetData(atoms.ToArray());

        //string csvPath = @"D:\Projects\Unity\unity-ray-marching-volumetric-textures\unity-ray-marching-volumetric-textures\tunnel\out\analysis\tunnel_profiles.csv";
        //spheres = new List<Vector4>();

        //foreach (var line in File.ReadAllLines(csvPath))
        //{
        //    if(line.StartsWith("Snapshot")) continue;

        //    var split = line.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

        //    if (String.CompareOrdinal(split[12].Trim(), "X") == 0)
        //    {
        //        for (int i = 13, j = 0; i < split.Length; i++, j ++)
        //        {
        //            spheres.Add(new Vector4(float.Parse(split[i]), 0, 0, 0));
        //        }
        //    }
        //    else
        //    {
        //        if (String.CompareOrdinal(split[12].Trim(), "Y") == 0)
        //        {
        //            for (int i = 13, j = 0; i < split.Length; i++, j++)
        //            {
        //                var v = new Vector4(spheres[j].x, float.Parse(split[i]), 0, 0);
        //                spheres[j] = v;
        //            }
        //        }
        //        if (String.CompareOrdinal(split[12].Trim(), "Z") == 0)
        //        {
        //            for (int i = 13, j = 0; i < split.Length; i++, j++)
        //            {
        //                var v = new Vector4(spheres[j].x, spheres[j].y, float.Parse(split[i]), 0);
        //                spheres[j] = v;
        //            }
        //        }
        //        if (String.CompareOrdinal(split[12].Trim(), "R") == 0)
        //        {
        //            for (int i = 13, j = 0; i < split.Length; i++, j++)
        //            {
        //                var v = new Vector4(spheres[j].x, spheres[j].y, spheres[j].z, float.Parse(split[i]));
        //                spheres[j] = v;
        //            }
        //        }
        //    }
        //}
    }
Example #6
0
    public void AddMoleculeType(string pdbName, Color color)
    {
        var path = Application.dataPath + "/Molecules/" + pdbName + ".pdb";

        if (!File.Exists(path))
        {
            throw new Exception("Pdb file does not exists");
        }

        var atoms = PdbReader.ReadPdbFile(path);

        var atomCount = new List <int>();

        if (_molAtomCountBuffer != null)  // if buffer alreay exists fetch information from the buffer
        {
            var temp = new int[_molAtomCountBuffer.count];
            _molAtomCountBuffer.GetData(temp);
            atomCount = new List <int>(temp);
        }

        var atomStart = new List <int>();

        if (_molAtomStartBuffer != null)
        {
            var temp = new int[_molAtomStartBuffer.count];
            _molAtomStartBuffer.GetData(temp);
            atomStart = new List <int>(temp);
        }

        var atomDataPdb = new List <Vector4>();

        if (_atomDataPdbBuffer != null)
        {
            var temp = new Vector4[_atomDataPdbBuffer.count];
            _atomDataPdbBuffer.GetData(temp);
            atomDataPdb = new List <Vector4>(temp);
        }

        atomCount.Add(atoms.Count);
        atomStart.Add(atomDataPdb.Count);
        atomDataPdb.AddRange(atoms);

        if (_molAtomCountBuffer != null)
        {
            _molAtomCountBuffer.Release();
        }
        _molAtomCountBuffer = new ComputeBuffer(atomCount.Count, 4);
        _molAtomCountBuffer.SetData(atomCount.ToArray());

        if (_molAtomStartBuffer != null)
        {
            _molAtomCountBuffer.Release();
        }
        _molAtomStartBuffer = new ComputeBuffer(atomStart.Count, 4);
        _molAtomStartBuffer.SetData(atomStart.ToArray());

        if (_atomDataPdbBuffer != null)
        {
            _molAtomCountBuffer.Release();
        }
        _atomDataPdbBuffer = new ComputeBuffer(atomDataPdb.Count, 16);
        _atomDataPdbBuffer.SetData(atomDataPdb.ToArray());

        MolNames.Add(name);

        Array.Resize(ref MolColors, MolColors.Length + 1);
        MolColors[MolColors.Length - 1] = color;
    }