Skip to content

Commit

Permalink
Merge pull request #1040 from papillot/1015-Binary-Cif-support
Browse files Browse the repository at this point in the history
1015 binary cif support
  • Loading branch information
ppillot authored May 24, 2024
2 parents 62ac286 + cc34e1d commit 3d7c96a
Show file tree
Hide file tree
Showing 21 changed files with 6,795 additions and 15,945 deletions.
4 changes: 3 additions & 1 deletion examples/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ NGL.MenubarFileWidget = function (stage) {

function onPdbInputKeyDown (e) {
if (e.keyCode === 13) {
stage.loadFile('rcsb://' + e.target.value.trim(), {
const val = e.target.value.trim()
const protocol = val.startsWith('AF_') ? 'rcsb://' : 'pdbe://'
stage.loadFile(protocol + val, {
defaultRepresentation: true
})
e.target.value = ''
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/showcase/viruses.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createElement (name, properties, style) {
return el
}

var pdbs = [ '1stm', '3nap', '1sid', '2ft1', '4cwu' ]
var pdbs = [ '1stm', '3nap', '1sid', '2ft1', '6cgv' ]
var colors = [ 'red', 'yellow', 'green', 'lightblue', 'violet' ]

Promise.all(pdbs.map(function (id) {
Expand Down
21,160 changes: 5,959 additions & 15,201 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 6 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prebuild": "npm run lint",
"build": "npm run dts && rollup -c",
"postbuild": "node ./scripts/makeScriptsList.js",
"test": "jest",
"test": "vitest --globals",
"preversion": "npm test",
"version": "npm run build-min && git add -A dist",
"postversion": "git push && git push --tags",
Expand All @@ -27,17 +27,6 @@
"prerelease": "./scripts/release.sh prerelease",
"build-min": "npm run lint && npm run dts && rollup -c rollup.config.dist.js"
},
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"transform": {
"\\.ts$": "ts-jest",
"\\.es6\\.js": "babel-jest"
},
"testRegex": "\\.spec\\.ts|kin.*test.ts$"
},
"homepage": "https://github.com/arose/ngl#readme",
"repository": {
"type": "git",
Expand Down Expand Up @@ -67,24 +56,23 @@
"@rollup/plugin-typescript": "^8.1.1",
"@types/chroma-js": "^1.3.5",
"@types/jest": "^27.5.1",
"@types/node": "^10.17.9",
"@types/offscreencanvas": "^2019.6.4",
"@types/signals": "1.0.1",
"@types/sprintf-js": "^1.1.2",
"@types/three": "^0.158.2",
"@yushijinhun/three-minifier-rollup": "^0.3.1",
"babel-plugin-array-includes": "^2.0.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^24.0.0",
"rollup": "^2.38.5",
"standard": "^17.1.0",
"ts-jest": "^29.1.1",
"standard": "^11.0.1",
"tslib": "^2.3.1",
"typedoc": "^0.22.15",
"typescript": "^4.5.4"
"typescript": "^4.5.4",
"vitest": "^1.5.2"
},
"dependencies": {
"chroma-js": "^1.3.7",
"molstar": "^4.1.0",
"signals": "^1.0.0",
"sprintf-js": "^1.1.2",
"three": "^0.158.0"
Expand Down
5 changes: 2 additions & 3 deletions src/datasource/alphafold-datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
*/

import { Log, DatasourceRegistry } from '../globals'
import { getProtocol } from '../utils'
import { getFileInfo } from '../loader/loader-utils'
import Datasource from './datasource'

const baseUrl = '//alphafold.ebi.ac.uk/files/AF-'
const suffixURL = '-F1-model_v2.pdb'
const suffixURL = '-F1-model_v4.pdb'

class AlphafoldDatasource extends Datasource {
getUrl (src: string) {
Expand All @@ -23,7 +22,7 @@ class AlphafoldDatasource extends Datasource {
Log.warn('unsupported AF ext', info.ext)
url = baseUrl + uniprotid + suffixURL
}
return getProtocol() + url
return 'https://' + url
}

getExt (src: string) {
Expand Down
58 changes: 58 additions & 0 deletions src/datasource/pdbe-datasource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file PDB Europe Datasource
* @author Paul Pillot <paul.pillot@tandemai.com>
* @private
*/

import { Log, DatasourceRegistry } from '../globals'
import { getFileInfo } from '../loader/loader-utils'
import Datasource from './datasource'

const baseUrl = '//www.ebi.ac.uk/pdbe/entry-files/download/'

// Examples:
//https://www.ebi.ac.uk/pdbe/entry-files/download/5z6y_updated.cif
//https://www.ebi.ac.uk/pdbe/entry-files/download/pdb5z6y.ent
//https://www.ebi.ac.uk/pdbe/entry-files/download/5z6y.bcif

class PDBeDatasource extends Datasource {
getUrl (src: string) {
// valid path are
// XXXX.pdb, XXXX.ent, XXXX.cif, XXXX.bcif
// XXXX defaults to XXXX.bcif
const info = getFileInfo(src)
let pdbid = info.name.indexOf('_') > -1 ? info.name : info.name.substring(0, 4) // Allow extended pdb codes
let url
switch (info.ext) {
case 'cif':
url = baseUrl + pdbid + '_updated.cif' // "Updated mmcif" files contain connectivity
break
case 'pdb':
case 'ent':
if (!pdbid.startsWith('pdb')) {
pdbid = 'pdb' + pdbid
}
url = baseUrl + pdbid + '.ent'
break
case 'bcif':
url = baseUrl + info.path
break
case '':
url = baseUrl + pdbid + '.bcif'
break
default:
Log.warn('unsupported ext', info.ext)
url = baseUrl + pdbid + '.bcif'
}
return 'https://' + url
}

getExt (src: string) {
const ext = getFileInfo(src).ext
return ext ? ext : 'mmtf'
}
}

DatasourceRegistry.add('pdbe', new PDBeDatasource())

export default PDBeDatasource
13 changes: 10 additions & 3 deletions src/datasource/rcsb-datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,37 @@ const baseUrl = '//files.rcsb.org/download/'
const mmtfBaseUrl = '//mmtf.rcsb.org/v1.0/'
const mmtfFullUrl = mmtfBaseUrl + 'full/'
const mmtfReducedUrl = mmtfBaseUrl + 'reduced/'
const bcifBaseUrl = '//models.rcsb.org/'

class RcsbDatasource extends Datasource {
getUrl (src: string) {
// valid path are
// XXXX.pdb, XXXX.pdb.gz, XXXX.cif, XXXX.cif.gz, XXXX.mmtf, XXXX.bb.mmtf
// XXXX defaults to XXXX.cif
const info = getFileInfo(src)
const pdbid = info.name.substr(0, 4)
const pdbid = info.name.indexOf('_') > -1 ? info.name : info.name.substring(0, 4) // Allow extended pdb codes and alphafold codes
let url
if ([ 'pdb', 'cif' ].includes(info.ext) &&
(info.compressed === false || info.compressed === 'gz')
) {
url = baseUrl + info.path
} else if (info.ext === 'mmtf') {
Log.warn('MMTF files distribution is discontinued by RCSB PDB as of July 2, 2024.\n Consider using bcif format instead. See https://www.rcsb.org/news/65a1af31c76ca3abcc925d0c for the deprecation notice')
if (info.base.endsWith('.bb')) {
url = mmtfReducedUrl + pdbid
} else {
url = mmtfFullUrl + pdbid
}
} else if (info.ext === 'bcif' &&
(info.compressed === false || info.compressed === 'gz')
) {
url = bcifBaseUrl + info.path
} else if (!info.ext) {
url = mmtfFullUrl + pdbid
Log.warn('mmCif files available from RCSB PDB lack connectivity information.\n Consider using PDBe as the data provider for using "Updated mmCif files" that contain residues connectivity records.')
url = bcifBaseUrl + pdbid + '.bcif.gz'
} else {
Log.warn('unsupported ext', info.ext)
url = mmtfFullUrl + pdbid
url = bcifBaseUrl + pdbid + '.bcif.gz'
}
return getProtocol() + url
}
Expand Down
1 change: 1 addition & 0 deletions src/ngl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ import './utils/gzip-decompressor'
//

import './datasource/rcsb-datasource'
import './datasource/pdbe-datasource'
import './datasource/pubchem-datasource'
import './datasource/passthrough-datasource'
import './datasource/alphafold-datasource'
Expand Down
Loading

0 comments on commit 3d7c96a

Please sign in to comment.