text: /**
   * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
   *
   * @author Alexander Rose <alexander.rose@weirdbyte.de>
   */
  import { __assign, __awaiter, __generator } from "tslib";
  import { DSSPComputationParams, computeUnitDSSP } from './secondary-structure/dssp';
  import { ParamDefinition as PD } from '../../mol-util/param-definition';
  import { Unit } from '../../mol-model/structure/structure';
  import { CustomStructureProperty } from '../common/custom-structure-property';
  import { ModelSecondaryStructure } from '../../mol-model-formats/structure/property/secondary-structure';
  import { CustomPropertyDescriptor } from '../../mol-model/custom-property';
  import { Model } from '../../mol-model/structure/model';
  function getSecondaryStructureParams(data) {
      var defaultType = 'model';
      if (data) {
          defaultType = 'dssp';
          for (var i = 0, il = data.models.length; i < il; ++i) {
              var m = data.models[i];
              if (Model.isFromPdbArchive(m) || Model.hasSecondaryStructure(m)) {
                  // if there is any secondary structure definition given or if there is
                  // an archival model, don't calculate dssp by default
                  defaultType = 'model';
                  break;
              }
          }
      }
      return {
          type: PD.MappedStatic(defaultType, {
              'model': PD.EmptyGroup({ label: 'Model' }),
              'dssp': PD.Group(DSSPComputationParams, { label: 'DSSP', isFlat: true })
          }, { options: [['model', 'Model'], ['dssp', 'DSSP']] })
      };
  }
  export var SecondaryStructureParams = getSecondaryStructureParams();
  export var SecondaryStructureProvider = CustomStructureProperty.createProvider({
      label: 'Secondary Structure',
      descriptor: CustomPropertyDescriptor({
          name: 'molstar_computed_secondary_structure',
          // TODO `cifExport` and `symbol`
      }),
      type: 'root',
      defaultParams: SecondaryStructureParams,
      getParams: getSecondaryStructureParams,
      isApplicable: function (data) { return true; },
      obtain: function (ctx, data, props) { return __awaiter(void 0, void 0, void 0, function () {
          var p, _a;
          var _b, _c;
          return __generator(this, function (_d) {
              switch (_d.label) {
                  case 0:
                      p = __assign(__assign({}, PD.getDefaultValues(SecondaryStructureParams)), props);
                      _a = p.type.name;
                      switch (_a) {
                          case 'dssp': return [3 /*break*/, 1];
                          case 'model': return [3 /*break*/, 3];
                      }
                      return [3 /*break*/, 5];
                  case 1:
                      _b = {};
                      return [4 /*yield*/, computeDssp(data, p.type.params)];
                  case 2: return [2 /*return*/, (_b.value = _d.sent(), _b)];
                  case 3:
                      _c = {};
                      return [4 /*yield*/, computeModel(data)];
                  case 4: return [2 /*return*/, (_c.value = _d.sent(), _c)];
                  case 5: return [2 /*return*/];
              }
          });
      }); }
  });
  function computeDssp(structure, props) {
      return __awaiter(this, void 0, void 0, function () {
          var map, i, il, u, secondaryStructure;
          return __generator(this, function (_a) {
              switch (_a.label) {
                  case 0:
                      map = new Map();
                      i = 0, il = structure.unitSymmetryGroups.length;
                      _a.label = 1;
                  case 1:
                      if (!(i < il)) return [3 /*break*/, 4];
                      u = structure.unitSymmetryGroups[i].units[0];
                      if (!(Unit.isAtomic(u) && !Model.isCoarseGrained(u.model))) return [3 /*break*/, 3];
                      return [4 /*yield*/, computeUnitDSSP(u, props)];
                  case 2:
                      secondaryStructure = _a.sent();
                      map.set(u.invariantId, secondaryStructure);
                      _a.label = 3;
                  case 3:
                      ++i;
                      return [3 /*break*/, 1];
                  case 4: return [2 /*return*/, map];
              }
          });
      });
  }
  function computeModel(structure) {
      return __awaiter(this, void 0, void 0, function () {
          var map, i, il, u, secondaryStructure;
          return __generator(this, function (_a) {
              map = new Map();
              for (i = 0, il = structure.unitSymmetryGroups.length; i < il; ++i) {
                  u = structure.unitSymmetryGroups[i].units[0];
                  if (Unit.isAtomic(u)) {
                      secondaryStructure = ModelSecondaryStructure.Provider.get(u.model);
                      if (secondaryStructure) {
                          map.set(u.invariantId, secondaryStructure);
                      }
                  }
              }
              return [2 /*return*/, map];
          });
      });
  }
  //# sourceMappingURL=secondary-structure.js.map