sequence.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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 { Structure } from '../../structure';
  9. import { CifExportContext } from '../mmcif';
  10. import { getModelMmCifCategory, getUniqueEntityIdsFromStructures } from './utils';
  11. import CifCategory = CifWriter.Category
  12. export const _struct_asym: CifCategory<CifExportContext> = createCategory('struct_asym');
  13. export const _entity_poly: CifCategory<CifExportContext> = createCategory('entity_poly');
  14. export const _entity_poly_seq: CifCategory<CifExportContext> = createCategory('entity_poly_seq');
  15. function createCategory(categoryName: 'struct_asym' | 'entity_poly' | 'entity_poly_seq'): CifCategory<CifExportContext> {
  16. return {
  17. name: categoryName,
  18. instance({ structures, cache }) {
  19. return getCategoryInstance(structures, categoryName, cache);
  20. }
  21. };
  22. }
  23. function getCategoryInstance(structures: Structure[], categoryName: 'struct_asym' | 'entity_poly' | 'entity_poly_seq', cache: any) {
  24. const category = getModelMmCifCategory(structures[0].model, categoryName);
  25. if (!category) return CifCategory.Empty;
  26. const { entity_id } = category;
  27. const names = cache.uniqueEntityIds || (cache.uniqueEntityIds = getUniqueEntityIdsFromStructures(structures));
  28. const indices = Column.indicesOf(entity_id, id => names.has(id));
  29. return CifCategory.ofTable(category, indices);
  30. }