Skip to content
Snippets Groups Projects
Select Git revision
  • b5fc24056ede0e3f539e16704fa86c938a7ba8d5
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

lookup3d.ts

Blame
  • user avatar
    David Sehnal authored
    e0283d88
    History
    lookup3d.ts 1.98 KiB
    import * as util from 'util'
    import * as fs from 'fs'
    import CIF from 'mol-io/reader/cif'
    
    import { Structure, Model, Format } from 'mol-model/structure'
    
    import { GridLookup3D } from 'mol-math/geometry';
    // import { sortArray } from 'mol-data/util';
    import { OrderedSet } from 'mol-data/int';
    
    require('util.promisify').shim();
    const readFileAsync = util.promisify(fs.readFile);
    
    async function readData(path: string) {
        if (path.match(/\.bcif$/)) {
            const input = await readFileAsync(path)
            const data = new Uint8Array(input.byteLength);
            for (let i = 0; i < input.byteLength; i++) data[i] = input[i];
            return data;
        } else {
            return readFileAsync(path, 'utf8');
        }
    }
    
    
    export async function readCIF(path: string) {
        const input = await readData(path)
        const comp = typeof input === 'string' ? CIF.parseText(input) : CIF.parseBinary(input);
        const parsed = await comp.run();
        if (parsed.isError) {
            throw parsed;
        }
    
        const mmcif = Format.mmCIF(parsed.result.blocks[0]);
        const models = await Model.create(mmcif).run();
        const structures = models.map(Structure.ofModel);
    
        return { mmcif: mmcif.data, models, structures };
    }
    
    export async function test() {
        const { mmcif, structures } = await readCIF('e:/test/quick/1tqn_updated.cif');
    
        const lookup = GridLookup3D({ x: mmcif.atom_site.Cartn_x.toArray(), y: mmcif.atom_site.Cartn_y.toArray(), z: mmcif.atom_site.Cartn_z.toArray(),
            indices: OrderedSet.ofBounds(0, mmcif.atom_site._rowCount),
            //radius: [1, 1, 1, 1]
            //indices: [1]
        });
        console.log(lookup.boundary.box, lookup.boundary.sphere);
    
        const result = lookup.find(-30.07, 8.178, -13.897, 10);
        console.log(result.count)//, sortArray(result.indices));
    
        // const sl = structures[0].lookup3d;
        // const result1 = sl.find(-30.07, 8.178, -13.897, 10);
        // console.log(result1.count);//, result1.indices);
    
        console.log(structures[0].boundary);
        console.log(lookup.boundary);
    }
    
    test();