/* Read full (with hash chains, for future modifying) * * lzw dictionary function */ void LzwDict::load( Scanner &_scanner ) { int i, j, HashCode, n, k; _modified = false; _alphabetSize = _scanner.readBinaryInt(); _nextCode = _scanner.readBinaryInt(); n = _scanner.readBinaryInt(); _bitcodeSize = _scanner.readBinaryInt(); _maxCode = (1 << _bitcodeSize) - 1; _storage.clear(); _storage.resize(n); for (i = 0; i < n; i++) { k = _scanner.readBinaryDword(); _storage[i].Prefix = k; _storage[i].AppendChar = _scanner.readByte(); } _freePtr = _scanner.readBinaryInt(); _hashKeys.clear_resize(SIZE); _nextPointers.clear_resize(SIZE); for (i = 0; i < SIZE; i++) { _nextPointers[i] = -1; _hashKeys[i] = -1; } while (!_scanner.isEOF()) { HashCode = _scanner.readBinaryInt(); j = _scanner.readBinaryInt(); _hashKeys[HashCode] = j; i = j; j = _scanner.readBinaryInt(); while (j != -1) { _nextPointers[i] = j; i = j; j = _scanner.readBinaryInt(); } } }
void CmfLoader::loadXyz (Scanner &scanner) { if (_mol == 0) throw Error("loadMolecule() must be called prior to loadXyz()"); int i; CmfSaver::VecRange range; range.xyz_min.x = scanner.readBinaryFloat(); range.xyz_min.y = scanner.readBinaryFloat(); range.xyz_min.z = scanner.readBinaryFloat(); range.xyz_range.x = scanner.readBinaryFloat(); range.xyz_range.y = scanner.readBinaryFloat(); range.xyz_range.z = scanner.readBinaryFloat(); range.have_z = (scanner.readByte() != 0); for (i = 0; i < _atoms.size(); i++) { Vec3f pos; _readVec3f(scanner, pos, range); int idx = i; if (has_mapping) idx = inv_atom_mapping_to_restore[i]; _mol->setAtomXyz(idx, pos.x, pos.y, pos.z); } // Read sgroup coordinates data int idx[5] = {0}; for (int i = 0; i < _sgroup_order.size(); i++) _readSGroupXYZ(scanner, _sgroup_order[i], idx, *_mol, range); _mol->have_xyz = true; }
bool MoleculeAutoLoader::tryMDLCT (Scanner &scanner, Array<char> &outbuf) { int pos = scanner.tell(); bool endmark = false; QS_DEF(Array<char>, curline); outbuf.clear(); while (!scanner.isEOF()) { int len = scanner.readByte(); if (len > 90) // Molfiles and Rxnfiles actually have 80 characters limit { scanner.seek(pos, SEEK_SET); // Garbage after endmark means end of data. // (See the note below about endmarks) if (endmark) return true; return false; } curline.clear(); while (len-- > 0) { if (scanner.isEOF()) { scanner.seek(pos, SEEK_SET); return false; } int c = scanner.readChar(); curline.push(c); } curline.push(0); if (endmark) { // We can not properly read the data to the end as there // is often garbage after the actual MDLCT data. // Instead, we are doing this lousy check: // "M END" or "$END MOL" can be followed only // by "$END CTAB" (in Markush queries), or // by "$MOL" (in Rxnfiles). Otherwise, this // is actually the end of data. if (strcmp(curline.ptr(), "$END CTAB") != 0 && strcmp(curline.ptr(), "$MOL") != 0) { scanner.seek(pos, SEEK_SET); return true; } } if (strcmp(curline.ptr(), "M END") == 0) endmark = true; else if (strcmp(curline.ptr(), "$END MOL") == 0) endmark = true; else endmark = false; outbuf.appendString(curline.ptr(), false); outbuf.push('\n'); } scanner.seek(pos, SEEK_SET); // It happened once that a valid Molfile had successfully // made its way through the above while() cycle, and thus // falsely recognized as MDLCT. To fight this case, we include // here a check that the last line was actually an endmark return endmark; }