misc.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { Column } from 'mol-data/db';
  7. import { CifWriter } from 'mol-io/writer/cif';
  8. import { CifExportContext } from '../mmcif';
  9. import { getModelMmCifCategory, getUniqueResidueNamesFromStructures } from './utils';
  10. import CifCategory = CifWriter.Category
  11. export const _chem_comp: CifCategory<CifExportContext> = {
  12. name: 'chem_comp',
  13. instance({ firstModel, structures, cache }) {
  14. const chem_comp = getModelMmCifCategory(structures[0].model, 'chem_comp');
  15. if (!chem_comp) return CifCategory.Empty;
  16. const { id } = chem_comp;
  17. const names = cache.uniqueResidueNames || (cache.uniqueResidueNames = getUniqueResidueNamesFromStructures(structures));
  18. const indices = Column.indicesOf(id, id => names.has(id));
  19. return CifCategory.ofTable(chem_comp, indices);
  20. }
  21. }
  22. export const _pdbx_chem_comp_identifier: CifCategory<CifExportContext> = {
  23. name: 'pdbx_chem_comp_identifier',
  24. instance({ firstModel, structures, cache }) {
  25. const pdbx_chem_comp_identifier = getModelMmCifCategory(firstModel, 'pdbx_chem_comp_identifier');
  26. if (!pdbx_chem_comp_identifier) return CifCategory.Empty;
  27. const { comp_id } = pdbx_chem_comp_identifier;
  28. const names = cache.uniqueResidueNames || (cache.uniqueResidueNames = getUniqueResidueNamesFromStructures(structures));
  29. const indices = Column.indicesOf(comp_id, id => names.has(id));
  30. return CifCategory.ofTable(pdbx_chem_comp_identifier, indices);
  31. }
  32. }