macroproperties.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Koya Sakuma <koya.sakuma.work@gmail.com>
  5. */
  6. import { MolScriptBuilder } from '../../../mol-script/language/builder';
  7. const B = MolScriptBuilder;
  8. import { PropertyDict } from '../types';
  9. // const reFloat = /[-+]?[0-9]*\.?[0-9]+/;
  10. // const rePosInt = /[0-9]+/;
  11. function atomNameListMap(x: string) { return x.split(',').map(B.atomName); }
  12. function listMap(x: string) { return x.split(',').map(x => x.replace(/^["']|["']$/g, '')); }
  13. function rangeMap(x: string) {
  14. const [min, max] = x.split('-').map(x => parseInt(x));
  15. return { min, max };
  16. }
  17. function listOrRangeMap(x: string) {
  18. if (x.includes('-') && x.includes(',')) {
  19. const pSplit = x.split(',').map(x => x.replace(/^["']|["']$/g, ''));
  20. console.log(pSplit);
  21. const res: number[] = [];
  22. pSplit.forEach(x => {
  23. if (x.includes('-')) {
  24. const [min, max] = x.split('-').map(x=>parseInt(x));
  25. for (let i = min; i <= max; i++) {
  26. res.push(i);
  27. }
  28. } else {
  29. res.push(parseInt(x));
  30. }
  31. });
  32. return res;
  33. } else if (x.includes('-') && !x.includes(',')) {
  34. return rangeMap(x);
  35. } else if (!x.includes('-') && x.includes(',')) {
  36. return listMap(x).map(x => parseInt(x));
  37. } else {
  38. return parseInt(x);
  39. }
  40. }
  41. function elementListMap(x: string) {
  42. return x.split(',').map(B.struct.type.elementSymbol);
  43. }
  44. // const sstrucDict: { [k: string]: string } = {
  45. // H: 'helix',
  46. // S: 'beta',
  47. // L: 'none'
  48. // };
  49. // function sstrucListMap(x: string) {
  50. // return {
  51. // flags: B.struct.type.secondaryStructureFlags(
  52. // x.toUpperCase().split('+').map(ss => sstrucDict[ss] || 'none')
  53. // )
  54. // };
  55. // }
  56. export const macroproperties: PropertyDict = {
  57. symbol: {
  58. '@desc': 'chemical-symbol-list: list of 1- or 2-letter chemical symbols from the periodic table',
  59. '@examples': ['symbol O+N'],
  60. abbr: ['e.'], regex: /[a-zA-Z'",]+/, map: elementListMap,
  61. level: 'atom-test', property: B.acp('elementSymbol')
  62. },
  63. name: {
  64. '@desc': 'atom-name-list: list of up to 4-letter codes for atoms in proteins or nucleic acids',
  65. '@examples': ['name CA+CB+CG+CD'],
  66. abbr: ['n.'], regex: /[a-zA-Z0-9'",]+/, map: atomNameListMap,
  67. level: 'atom-test', property: B.ammp('label_atom_id')
  68. },
  69. resn: {
  70. '@desc': 'residue-name-list: list of 3-letter codes for amino acids or list of up to 2-letter codes for nucleic acids',
  71. '@examples': ['resn ASP+GLU+ASN+GLN', 'resn A+G'],
  72. abbr: ['resname', 'r.'], regex: /[a-zA-Z0-9'",]+/, map: listMap,
  73. level: 'residue-test', property: B.ammp('label_comp_id')
  74. },
  75. resi: {
  76. '@desc': 'residue-identifier-list list of up to 4-digit residue numbers or residue-identifier-range',
  77. '@examples': ['resi 1+10+100+1000', 'resi 1-10'],
  78. abbr: ['resident', 'residue', 'resid', 'i.'], regex: /[0-9,-]+/, map: listOrRangeMap,
  79. level: 'residue-test', property: B.ammp('auth_seq_id')
  80. },
  81. alt: {
  82. '@desc': 'alternate-conformation-identifier-list list of single letters',
  83. '@examples': ['alt A+B', 'alt ""', 'alt ""+A'],
  84. abbr: [], regex: /[a-zA-Z0-9'",]+/, map: listMap,
  85. level: 'atom-test', property: B.ammp('label_alt_id')
  86. },
  87. chain: {
  88. '@desc': 'chain-identifier-list list of single letters or sometimes numbers',
  89. '@examples': ['chain A'],
  90. abbr: ['c.'], regex: /[a-zA-Z0-9'",]+/, map: listMap,
  91. level: 'chain-test', property: B.ammp('auth_asym_id')
  92. },
  93. };