Best JavaScript code snippet using root
properties.ts
Source:properties.ts
...29 // Conformation30 x: p(l => l.unit.conformation.x(l.element)),31 y: p(l => l.unit.conformation.y(l.element)),32 z: p(l => l.unit.conformation.z(l.element)),33 id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicConformation.atomId.value(l.element)),34 occupancy: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicConformation.occupancy.value(l.element)),35 B_iso_or_equiv: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicConformation.B_iso_or_equiv.value(l.element)),36 sourceIndex: p(l => Unit.isAtomic(l.unit)37 ? l.unit.model.atomicHierarchy.atomSourceIndex.value(l.element)38 // TODO: when implemented, this should map to the source index.39 : l.element),40 // Hierarchy41 type_symbol: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.atoms.type_symbol.value(l.element)),42 label_atom_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.atoms.label_atom_id.value(l.element)),43 auth_atom_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.atoms.auth_atom_id.value(l.element)),44 label_alt_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.atoms.label_alt_id.value(l.element)),45 label_comp_id: p(compId),46 auth_comp_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.atoms.auth_comp_id.value(l.element)),47 pdbx_formal_charge: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.atoms.pdbx_formal_charge.value(l.element)),48 // Derived49 vdw_radius: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : VdwRadius(l.unit.model.atomicHierarchy.atoms.type_symbol.value(l.element))),50};51function compId(l: StructureElement.Location) {52 if (!Unit.isAtomic(l.unit)) notAtomic();53 return l.unit.model.atomicHierarchy.atoms.label_comp_id.value(l.element);54}55function seqId(l: StructureElement.Location) {56 return !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.residues.label_seq_id.value(l.unit.residueIndex[l.element]);57}58function hasMicroheterogeneity(l: StructureElement.Location) {59 if (!Unit.isAtomic(l.unit)) notAtomic();60 const entitySeq = l.unit.model.sequence.byEntityKey[eK(l)];61 return entitySeq && entitySeq.sequence.microHet.has(seqId(l));62}63function microheterogeneityCompIds(l: StructureElement.Location) {64 if (!Unit.isAtomic(l.unit)) notAtomic();65 const entitySeq = l.unit.model.sequence.byEntityKey[eK(l)];66 if (entitySeq) {67 return entitySeq.sequence.microHet.get(seqId(l)) || [compId(l)];68 } else {69 return [compId(l)];70 }71}72const residue = {73 key: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.residueIndex[l.element]),74 group_PDB: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.residues.group_PDB.value(l.unit.residueIndex[l.element])),75 label_seq_id: p(seqId),76 auth_seq_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.residues.auth_seq_id.value(l.unit.residueIndex[l.element])),77 pdbx_PDB_ins_code: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.residues.pdbx_PDB_ins_code.value(l.unit.residueIndex[l.element])),78 // Properties79 isNonStandard: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : microheterogeneityCompIds(l).some(c => l.unit.model.properties.chemicalComponentMap.get(c)!.mon_nstd_flag[0] === 'n')),80 hasMicroheterogeneity: p(hasMicroheterogeneity),81 microheterogeneityCompIds: p(microheterogeneityCompIds),82 secondary_structure_type: p(l => {83 if (!Unit.isAtomic(l.unit)) notAtomic();84 const secStruc = SecondaryStructureProvider.get(l.structure).value?.get(l.unit.invariantId);85 return secStruc?.type[l.unit.residueIndex[l.element]] ?? SecondaryStructureType.Flag.NA;86 }),87 secondary_structure_key: p(l => {88 if (!Unit.isAtomic(l.unit)) notAtomic();89 const secStruc = SecondaryStructureProvider.get(l.structure).value?.get(l.unit.invariantId);90 return secStruc?.key[l.unit.residueIndex[l.element]] ?? -1;91 }),92 chem_comp_type: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.properties.chemicalComponentMap.get(compId(l))!.type),93};94const chain = {95 key: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.chainIndex[l.element]),96 label_asym_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.chains.label_asym_id.value(l.unit.chainIndex[l.element])),97 auth_asym_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.chains.auth_asym_id.value(l.unit.chainIndex[l.element])),98 label_entity_id: p(l => !Unit.isAtomic(l.unit) ? notAtomic() : l.unit.model.atomicHierarchy.chains.label_entity_id.value(l.unit.chainIndex[l.element]))99};100const coarse = {101 key: atom.key,102 entityKey: p(l => !Unit.isCoarse(l.unit) ? notCoarse() : l.unit.coarseElements.entityKey[l.element]),103 x: atom.x,104 y: atom.y,105 z: atom.z,106 asym_id: p(l => !Unit.isCoarse(l.unit) ? notCoarse() : l.unit.coarseElements.asym_id.value(l.element)),107 seq_id_begin: p(l => !Unit.isCoarse(l.unit) ? notCoarse() : l.unit.coarseElements.seq_id_begin.value(l.element)),108 seq_id_end: p(l => !Unit.isCoarse(l.unit) ? notCoarse() : l.unit.coarseElements.seq_id_end.value(l.element)),109 sphere_radius: p(l => !Unit.isSpheres(l.unit) ? notCoarse('spheres') : l.unit.coarseConformation.radius[l.element]),110 sphere_rmsf: p(l => !Unit.isSpheres(l.unit) ? notCoarse('spheres') : l.unit.coarseConformation.rmsf[l.element]),111 gaussian_weight: p(l => !Unit.isGaussians(l.unit) ? notCoarse('gaussians') : l.unit.coarseConformation.weight[l.element]),112 gaussian_covariance_matrix: p(l => !Unit.isGaussians(l.unit) ? notCoarse('gaussians') : l.unit.coarseConformation.covariance_matrix[l.element])...
FormattedSegment.js
Source:FormattedSegment.js
1'use strict';2const AtomicText = 'â²';3const Empty = {};4export default class FormattedSegment {5 /**6 * A formatted string consists of a sequence of formatted segments.7 * Each segment is expected to have an unique id (one is generated if not provided)8 * The flow mode is expected to capture the information on whether the segment is considered inline or block etc.9 * The isAtomic flag is used to determine if it is expected to be treated as one block of object for editing purposes.10 * The renderInfo is an opaque object that holds info on how to render this segment.11 *12 * This class is not sealed and it is acceptable for callers to override this and pass that to FormattedString.13 * @namespace string.formatted14 * @class FormattedSegment15 * @constructor16 */17 constructor({id=this.generateId(), text='', renderInfo=Empty, flowMode, isAtomic=false}) {18 this.id = id;19 this.text = text;20 this.flowMode = flowMode;21 this.isAtomic = isAtomic;22 this.renderInfo = renderInfo;23 if (isAtomic && !text) {24 this.text = AtomicText;25 }26 this.count = this.text.length;27 }28 /**29 * Returns a new segment which has the updated styles.30 * @method updateStyles31 * @param {Function|Object} styleUpdator - if this is an object, it is merged into the current renderInfo.32 * If a function is passed in as the styleUpdator param, it is called with the old renderInfo and is expected to return the new renderInfo.33 * @return FormattedSegment or this if there is no update34 */35 updateStyles(styleUpdator) {36 const updator = typeof styleUpdator == 'object' ? old => Object.assign({}, old, styleUpdator) : styleUpdator;37 const renderInfo = updator(this.renderInfo, this);38 if (renderInfo === this.renderInfo) return this;39 return new this.constructor({text: this.text, flowMode: this.flowMode, isAtomic: this.isAtomic, renderInfo});40 }41 /**42 * Returns a new segment that holds a slice of the contents of this with the same rendering43 * It is an error to try to slice into an atomic segment.44 * @method slice45 * @param {Number} start46 * @param {Number} end47 */48 slice(start, end) {49 const min = Math.max(0, Math.min(start, end, this.count));50 const max = Math.min(this.count, Math.max(start, end, 0));51 if (min === 0 && max === this.count) return this;52 if (this.isAtomic) throw new Error('Cannot slice atomic entries');53 const text = this.text.slice(min, max);54 const flowMode = this.flowMode;55 const isAtomic = this.isAtomic;56 return new this.constructor({text, renderInfo: this.renderInfo, flowMode, isAtomic});57 }58 /**59 * Splices a piece of text into the current segment. It is an error to splice into an atomic segment.60 * @method splice61 * @param {Number} start62 * @param {Number} deleteCount63 * @param {String} insertText - note that this is not a var-args and cannot be any type other than string.64 */65 splice(start, deleteCount, insertText='') {66 if (this.isAtomic) throw new Error('Cannot splice into atomic segments');67 const text = this.text.slice(0, start) + insertText + this.text.slice(start + deleteCount);68 const flowMode = this.flowMode;69 const isAtomic = this.isAtomic;70 return new this.constructor({text, renderInfo: this.renderInfo, flowMode, isAtomic});71 }72 /**73 * Converts this segment to the string. Derived classes can override this safely.74 * Default implementation simply returns the text basis with a special character (â²) for atomic objects.75 * @method toString76 */77 toString() {78 return this.text;79 }80 /**81 * Render the contents of this in the preferred mime type.82 * This is a generic function that can be used to render text, HTML or even React.83 * @method render84 */85 render(context, mimeType='text/plain') {86 if (mimeType === 'text/plain') return this.toString();87 }88 /**89 * Generates a unique id for use with this segment. Derived classes can overrid this safely.90 * @method generateId91 */92 generateId() {93 return'id' + Date.now().toString() + Math.floor(Math.random(1000)).toString();94 }95 /**96 * Creates text segments.97 * @method createTextSegment98 * @static99 */100 static createTextSegment(text, renderInfo) {101 return new this({text, renderInfo});102 }103 /**104 * Creates embedded (atomic) objects.105 * @method createEmbed106 * @static107 */108 static createEmbed(flowMode, renderInfo) {109 return new this({text: AtomicText, flowMode, renderInfo});110 }...
Using AI Code Generation
1var root = require('./root');2console.log(root.isAtomic(5));3console.log(root.isAtomic('5'));4console.log(root.isAtomic(5.5));5console.log(root.isAtomic('5.5'));6console.log(root.isAtomic(false));7console.log(root.isAtomic('false'));8console.log(root.isAtomic(true));9console.log(root.isAtomic('true'));10console.log(root.isAtomic(null));11console.log(root.isAtomic('null'));12console.log(root.isAtomic(undefined));13console.log(root.isAtomic('undefined'));14console.log(root.isAtomic({}));15console.log(root.isAtomic([]));16console.log(root.isAtomic(function(){}));17console.log(root.isAtomic(new Date()));18console.log(root.isAtomic(/a/));19console.log(root.isAtomic(new RegExp('a')));20console.log(root.isAtomic(new Error('a')));21console.log(root.isAtomic(new String('a')));22console.log(root.isAtomic(new Number(5)));23console.log(root.isAtomic(new Boolean(true)));
Using AI Code Generation
1var rootNode = require('./rootNode');2rootNode.isAtomic('a');3rootNode.isAtomic('b');4rootNode.isAtomic('c');5rootNode.isAtomic('d');6rootNode.isAtomic('e');7rootNode.isAtomic('f');8rootNode.isAtomic('g');9rootNode.isAtomic('h');10rootNode.isAtomic('i');11rootNode.isAtomic('j');12rootNode.isAtomic('k');13rootNode.isAtomic('l');14rootNode.isAtomic('m');15rootNode.isAtomic('n');16rootNode.isAtomic('o');17rootNode.isAtomic('p');18rootNode.isAtomic('q');19rootNode.isAtomic('r');20rootNode.isAtomic('s');21rootNode.isAtomic('t');22rootNode.isAtomic('u');23rootNode.isAtomic('v');24rootNode.isAtomic('w');25rootNode.isAtomic('x');26rootNode.isAtomic('y');27rootNode.isAtomic('z');28rootNode.isAtomic('A');29rootNode.isAtomic('B');30rootNode.isAtomic('C');31rootNode.isAtomic('D');32rootNode.isAtomic('E');33rootNode.isAtomic('F');34rootNode.isAtomic('G');35rootNode.isAtomic('H');36rootNode.isAtomic('I');37rootNode.isAtomic('J');38rootNode.isAtomic('K');39rootNode.isAtomic('L');40rootNode.isAtomic('M');41rootNode.isAtomic('N');42rootNode.isAtomic('O');43rootNode.isAtomic('P');44rootNode.isAtomic('Q');45rootNode.isAtomic('R');46rootNode.isAtomic('S');47rootNode.isAtomic('T');48rootNode.isAtomic('U');49rootNode.isAtomic('V');50rootNode.isAtomic('W');51rootNode.isAtomic('X');52rootNode.isAtomic('Y');53rootNode.isAtomic('Z');54rootNode.isAtomic('0');55rootNode.isAtomic('1');56rootNode.isAtomic('2');57rootNode.isAtomic('3');58rootNode.isAtomic('4');59rootNode.isAtomic('5');60rootNode.isAtomic('6');61rootNode.isAtomic('7');62rootNode.isAtomic('8');63rootNode.isAtomic('9');64rootNode.isAtomic('-');65rootNode.isAtomic('_');66rootNode.isAtomic(':');67rootNode.isAtomic('.');68rootNode.isAtomic(' ');69rootNode.isAtomic('!');70rootNode.isAtomic('#');71rootNode.isAtomic('$');72rootNode.isAtomic('%');
Using AI Code Generation
1var root = require('root');2var isAtomic = root.isAtomic;3var result = isAtomic(1);4var isAtomic = function(value) {5 return value === null || value === undefined || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';6};7module.exports = {8};9module.exports = isAtomic;10module.exports = {11};12module.exports = isAtomic;13module.exports = {14};
Using AI Code Generation
1var root = require('./root.js');2var num = 10;3if(root.isAtomic(num))4{5 console.log("Atomic");6}7{8 console.log("Not Atomic");9}10var isAtomic = function(num)11{12 if(num == 0 || num == 1) return false;13 for(var i = 2; i < num; i++)14 {15 if(num%i == 0) return false;16 }17 return true;18}19module.exports.isAtomic = isAtomic;20var isAtomic = function(num)21{22 if(num == 0 || num == 1) return false;23 for(var i = 2; i < num; i++)24 {25 if(num%i == 0) return false;26 }27 return true;28}29exports.isAtomic = isAtomic;30The require is a function that you use to include modules that exist in separate files. The require function allows you to include modules that are present in separate files. You can include core Node.js modules, community-based modules (node_modules), and local modules. For example, if you want to include the root.js file, you can do it as follows:31var root = require('./root.js');32var num = 10;33if(root.isAtomic(num))34{35 console.log("Atomic");36}37{38 console.log("Not Atomic");39}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!