import macro from 'vtk.js/Sources/macros'; import vtkMolecule from 'vtk.js/Sources/Common/DataModel/Molecule'; import DataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper';
import ATOMS from 'vtk.js/Utilities/XMLConverter/chemistry-mapper/elements.json';
import 'vtk.js/Sources/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper';
function vtkPDBReader(publicAPI, model) { model.classHierarchy.push('vtkPDBReader');
if (!model.dataAccessHelper) { model.dataAccessHelper = DataAccessHelper.get('http'); }
function fetchPDB(url, option) { return model.dataAccessHelper.fetchText(publicAPI, url, option); }
publicAPI.setUrl = (url, option) => { if (url.indexOf('.pdb') === -1) { model.baseURL = url; model.url = `${url}`; } else { model.url = url;
const path = url.split('/'); path.pop(); model.baseURL = path.join('/'); }
return publicAPI.loadData(option); };
publicAPI.loadData = (option) => fetchPDB(model.url, option).then(publicAPI.parseAsText);
publicAPI.parseAsText = (txt) => { model.pdb = txt; model.molecule = []; model.molecule = model.pdb.split('\n'); publicAPI.modified(); return true; };
publicAPI.requestData = (inData, outData) => { const moleculedata = vtkMolecule.newInstance();
if (model.molecule) { const jSize = model.molecule.length;
const pointValues = [];
const atomicNumber = [];
model.numberOfAtoms = 0;
let j = 0; while (j < jSize && model.molecule[j] !== 'END') { const iSize = model.molecule[j].length; const linebuf = model.molecule[j];
const command = linebuf.substr(0, 6).replace(/\s+/g, ''); command.toUpperCase();
if (command === 'ATOM' || command === 'HETATM') { const dum1 = linebuf.substr(12, 4).replace(/\s+/g, ''); const x = linebuf.substr(30, 8).replace(/\s+/g, ''); const y = linebuf.substr(38, 8).replace(/\s+/g, ''); const z = linebuf.substr(46, 8).replace(/\s+/g, '');
let elem = ''; if (iSize >= 78) { elem = linebuf.substr(76, 2).replace(/\s+/g, ''); } if (elem === '') { elem = dum1.substr(0, 2).replace(/\d/g, ''); }
pointValues.push(x); pointValues.push(y); pointValues.push(z);
const [atomicNumberData] = ATOMS[elem];
atomicNumber.push(atomicNumberData);
model.numberOfAtoms++; }
j++; }
moleculedata.getAtoms().elements = {}; moleculedata.getAtoms().elements.number = Int8Array.from(atomicNumber); moleculedata.getAtoms().coords = {}; moleculedata.getAtoms().coords['3d'] = Float32Array.from(pointValues); }
model.output[0] = moleculedata; };
publicAPI.isBusy = () => !!model.requestCount; }
const DEFAULT_VALUES = { numberOfAtoms: 0, requestCount: 0, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model); macro.get(publicAPI, model, [ 'url', 'baseURL', 'numberOfAtoms', 'requestCount', ]); macro.setGet(publicAPI, model, ['dataAccessHelper']); macro.algo(publicAPI, model, 0, 1); macro.event(publicAPI, model, 'busy');
vtkPDBReader(publicAPI, model); }
export const newInstance = macro.newInstance(extend, 'vtkPDBReader');
export default { newInstance, extend };
|