Skip to content

Add configuration object to the initializer #7

@dimin

Description

@dimin

I've had to do some funny stuff trying to initialize the view the way I want it... My suggestion would be to use a configuration object in the init as well as in the defineRepresentation. If you like my proposal I could add that into the newThreeJS branch.

How about something like this for default:
config = {
colorMode: 'chainbow', // ss chain chainbow b polarity
mainchainMode: 'ribbon', // ribbon thickRibbon strand chain cylinderHelix tube bonds
doNotSmoothen: true,
sideChainsAsLines: false,
baseMode: 'nuclLine', // na base: nuclStick nuclLine nuclPolygon
symopHetatms: false,
nbMode: null, // nb_sphere nb_cross
hetatmMode: 'sphere', // stick sphere line icosahedron ballAndStick ballAndStick2
projectionMode: 'perspective', // perspective orthoscopic
unitCell: false,
biomt: false,
packing: false,
bgcolor: 0x434343,
}

During init provided could be merged with the default one. It is easy to modify the config object in the instance and run rebuildScene and show to update the view. This could become a default defineRepresentation and would not need any more changes:

// extend glMol with additional configs
glmolDefineRepresentation = function() {
if (!this.config) {
var all = this.getAllAtoms();
var hetatm = this.removeSolvents(this.getHetatms(all));
this.colorByAtom(all, {});
this.colorByChain(all);

    this.drawAtomsAsSphere(this.modelGroup, hetatm, this.sphereRadius); 
    this.drawMainchainCurve(this.modelGroup, all, this.curveWidth, 'P');
    this.drawCartoon(this.modelGroup, all, this.curveWidth);
} else {
    var c = this.config,
        all = this.getAllAtoms();

    if (c.biomtChains) {
        all = this.getChain(all, c.biomtChains);
    }
    var allHet = this.getHetatms(all),
        hetatm = this.removeSolvents(allHet),
        asu = new THREE.Object3D(); 

    // color by
    this.colorByAtom(all, {});            
    if (c.colorMode === 'ss') {
        this.colorByStructure(all, 0xcc00cc, 0x00cccc);
    } else if (c.colorMode === 'chain') {
        this.colorByChain(all);
     } else if (c.colorMode === 'chainbow') {
        this.colorChainbow(all);
    } else if (c.colorMode === 'b') {
        this.colorByBFactor(all);
    } else if (c.colorMode === 'polarity') {
        this.colorByPolarity(all, 0xcc0000, 0xcccccc);
    } 

    // main chain
    // Don't smooth beta-sheets in ribbons: boolean
    if (c.mainchainMode) {
        if (c.mainchainMode === 'ribbon') {
            this.drawCartoon(asu, all, c.doNotSmoothen);
            this.drawCartoonNucleicAcid(asu, all);
        } else if (c.mainchainMode === 'thickRibbon') {
            this.drawCartoon(asu, all, c.doNotSmoothen, this.thickness);
            this.drawCartoonNucleicAcid(asu, all, null, this.thickness);
        } else if (c.mainchainMode === 'strand') {
            this.drawStrand(asu, all, null, null, null, null, null, c.doNotSmoothen);
            this.drawStrandNucleicAcid(asu, all);
        } else if (c.mainchainMode === 'chain') {
            this.drawMainchainCurve(asu, all, this.curveWidth, 'CA', 1);
            this.drawMainchainCurve(asu, all, this.curveWidth, 'O3\'', 1);
        } else if (c.mainchainMode === 'cylinderHelix') {
            this.drawHelixAsCylinder(asu, all, 1.6);
            this.drawCartoonNucleicAcid(asu, all);
        } else if (c.mainchainMode === 'tube') {
            this.drawMainchainTube(asu, all, 'CA');
            this.drawMainchainTube(asu, all, 'O3\''); // FIXME: 5' end problem!
        } else if (c.mainchainMode === 'bonds') {
            this.drawBondsAsLine(asu, all, this.lineWidth);
        }
    }

    // side chains as lines: boolean        
    if (c.sideChainsAsLines) {
        this.drawBondsAsLine(this.modelGroup, this.getSidechains(all), this.lineWidth);
    }        

    // nucleic acid bases as: sticks, lines, polygons
    if (c.baseMode) {
        if (c.baseMode === 'nuclStick') {
            this.drawNucleicAcidStick(this.modelGroup, all);
        } else if (c.baseMode === 'nuclLine') {
            this.drawNucleicAcidLine(this.modelGroup, all);
        } else if (c.baseMode === 'nuclPolygon') {
            this.drawNucleicAcidLadder(this.modelGroup, all);
        }
    }

    // Show HETATMs in symmetry mates (slower)
    var target = c.symopHetatms ? asu : this.modelGroup; 

    // Non-bonded atoms (solvent/ions) as
    if (c.nbMode) {
        var nonBonded = this.getNonbonded(allHet);
        if (c.nbMode === 'nb_sphere') {
            this.drawAtomsAsIcosahedron(target, nonBonded, 0.3, true);
        } else if (c.nbMode === 'nb_cross') {
            this.drawAsCross(target, nonBonded, 0.3, true);
        }
    }        

    // Small molecules(HETATMs) as: hidden, sticks, ball and stick, ball and stick (multi bond), spheres, icosahedrons, lines
    if (c.hetatmMode) {
        if (c.hetatmMode === 'stick') {
            this.drawBondsAsStick(target, hetatm, this.cylinderRadius, this.cylinderRadius, true);
        } else if (c.hetatmMode === 'sphere') {
            this.drawAtomsAsSphere(target, hetatm, this.sphereRadius);
        } else if (c.hetatmMode === 'line') {
            this.drawBondsAsLine(target, hetatm, this.curveWidth);
        } else if (c.hetatmMode === 'icosahedron') {
            this.drawAtomsAsIcosahedron(target, hetatm, this.sphereRadius);
        } else if (c.hetatmMode === 'ballAndStick') {
            this.drawBondsAsStick(target, hetatm, this.cylinderRadius / 2.0, this.cylinderRadius, true, false, 0.3);
        } else if (c.hetatmMode === 'ballAndStick2') {
            this.drawBondsAsStick(target, hetatm, this.cylinderRadius / 2.0, this.cylinderRadius, true, true, 0.3);
        } 
    }        

    // Projection: perspective, orthoscopic
    if (c.projectionMode === 'perspective') {
        this.camera = this.perspectiveCamera;
    } else if (c.projectionMode === 'orthoscopic') {
        this.camera = this.orthoscopicCamera;
    }

    // Background color 
    if (c.bgcolor !== null) {
        this.setBackground(c.bgcolor);
    }

    // Unit cell
    if (c.unitCell) {
        this.drawUnitcell(this.modelGroup);
    }

    // Biological assembly (the last one defined)
    if (c.biomt) {
        this.drawSymmetryMates2(this.modelGroup, asu, this.protein.biomtMatrices);
    }

    // Crystal packing
    if (c.packing) {
        this.drawSymmetryMatesWithTranslation2(this.modelGroup, asu, this.protein.symMat);
    }
    this.modelGroup.add(asu);        
}

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions