Compare commits

...

21 Commits

Author SHA1 Message Date
dsehnal
9bec644997 3.2.0 2022-02-17 19:24:55 +01:00
dsehnal
650d38dff8 Store IndexPairBonds as a dynamic property 2022-02-17 19:21:49 +01:00
David Sehnal
097277e397 Merge pull request #373 from JonStargaryen/master
Add TraceOnly option for Structure Superposition
2022-02-14 19:53:51 +01:00
Sebastian Bittrich
82a4d5eedf cleanup 2022-02-14 10:46:03 -08:00
Sebastian Bittrich
2a00248812 determine trace during buildIndex 2022-02-14 10:41:10 -08:00
Sebastian Bittrich
9841c773cb reset camera after all alignments 2022-02-10 13:55:09 -08:00
Sebastian Bittrich
b21a78ad14 support shuffled atoms when aligning SIFTS trace 2022-02-10 13:49:37 -08:00
Sebastian Bittrich
7329fa597d options obj for alignAndSuperposeWithSIFTSMapping 2022-02-10 11:36:50 -08:00
Sebastian Bittrich
f1d8f0ecb4 auth 2022-02-10 11:32:21 -08:00
Sebastian Bittrich
1d127f2364 changelog 2022-02-10 11:30:55 -08:00
Sebastian Bittrich
b244405cc3 polymer-based query 2022-02-10 10:39:22 -08:00
Sebastian Bittrich
38adfe0ca6 cleanup 2022-02-10 10:29:34 -08:00
Sebastian Bittrich
6f0d798847 optional filtering for trace during alignment 2022-02-10 10:23:31 -08:00
Sebastian Bittrich
6e58bfd2b0 traceOnly param for superpos 2022-02-08 16:03:05 -08:00
David Sehnal
bc2e8d8ac4 Merge pull request #369 from molstar/pdbx_sifts-export
Better support for atom_site.pdbx_sifts_xref
2022-02-08 10:19:02 +01:00
dsehnal
7be654d47f tweak labels 2022-02-08 10:18:01 +01:00
dsehnal
bfe46e3604 pdbx_sifts_xref PR feedback 2022-02-08 10:12:21 +01:00
dsehnal
008b597fc5 changelog 2022-02-07 17:51:13 +01:00
dsehnal
c4b4f2e3b1 rename BestDatabaseSequenceMapping -> SIFTSMapping 2022-02-07 17:49:10 +01:00
dsehnal
76ee97301b atom_site.pdbx_label_index support 2022-02-07 17:44:03 +01:00
dsehnal
289dc09eae add support for atom_site.pdbx_sifts_xref export 2022-02-07 17:33:11 +01:00
14 changed files with 284 additions and 97 deletions

View File

@@ -6,6 +6,14 @@ Note that since we don't clearly distinguish between a public and private interf
## [Unreleased]
## [v3.2.0] - 2022-02-17
- Rename "best database mapping" to "SIFTS Mapping"
- Add schema and export support for ``atom_site.pdbx_sifts_xref_*`` fields
- Add schema export support for ``atom_site.pdbx_label_index`` field
- Add `traceOnly` parameter to chain/UniProt-based structure alignment
- Store ``IndexPairBonds`` as a dynamic property.
## [v3.1.0] - 2022-02-06
- Fix ``xrayShaded`` & ``ignoreLight`` params not working at the same time

View File

@@ -24,6 +24,11 @@ atom_site.auth_asym_id
atom_site.auth_seq_id
atom_site.pdbx_PDB_model_num
atom_site.ihm_model_id
atom_site.pdbx_label_index
atom_site.pdbx_sifts_xref_db_name
atom_site.pdbx_sifts_xref_db_acc
atom_site.pdbx_sifts_xref_db_num
atom_site.pdbx_sifts_xref_db_res
atom_site_anisotrop.id
atom_site_anisotrop.U
1 atom_sites.entry_id
24 atom_site.pdbx_PDB_model_num
25 atom_site.ihm_model_id
26 atom_site_anisotrop.id atom_site.pdbx_label_index
27 atom_site.pdbx_sifts_xref_db_name
28 atom_site.pdbx_sifts_xref_db_acc
29 atom_site.pdbx_sifts_xref_db_num
30 atom_site.pdbx_sifts_xref_db_res
31 atom_site_anisotrop.id
32 atom_site_anisotrop.U
33 atom_site_anisotrop.U_esd
34 atom_site_anisotrop.pdbx_PDB_ins_code

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "molstar",
"version": "3.1.0",
"version": "3.2.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "molstar",
"version": "3.1.0",
"version": "3.2.0",
"license": "MIT",
"dependencies": {
"@types/argparse": "^2.0.10",

View File

@@ -1,6 +1,6 @@
{
"name": "molstar",
"version": "3.1.0",
"version": "3.2.0",
"description": "A comprehensive macromolecular library.",
"homepage": "https://github.com/molstar/molstar#readme",
"repository": {

View File

@@ -215,6 +215,28 @@ export const mmCIF_Schema = {
* formal charge assignment normally found in chemical diagrams.
*/
pdbx_formal_charge: int,
/**
* This data item is an ordinal which identifies distinct chemical components in the atom_site category, both
* polymeric and non-polymeric.
*/
pdbx_label_index: int,
/**
* The name of additional external databases with residue level mapping.
*/
pdbx_sifts_xref_db_name: str,
/**
* The accession code related to the additional external database entry.
*/
pdbx_sifts_xref_db_acc: str,
/**
* The sequence position of the external database entry that corresponds
* to the residue mapping defined by the SIFTS process.
*/
pdbx_sifts_xref_db_num: str,
/**
* Describes the residue type of the given UniProt match
*/
pdbx_sifts_xref_db_res: str,
/**
* The model id corresponding to the atom site.
* This data item is a pointer to _ihm_model_list.model_id

View File

@@ -1,7 +1,8 @@
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { Model } from '../../../mol-model/structure';
@@ -44,7 +45,7 @@ interface FormatPropertyProvider<T> {
}
namespace FormatPropertyProvider {
export function create<T>(descriptor: CustomPropertyDescriptor): FormatPropertyProvider<T> {
export function create<T>(descriptor: CustomPropertyDescriptor, options?: { asDynamic?: boolean }): FormatPropertyProvider<T> {
const { name } = descriptor;
const formatRegistry = new FormatRegistry<T>();
@@ -55,21 +56,31 @@ namespace FormatPropertyProvider {
return formatRegistry.isApplicable(model);
},
get(model: Model): T | undefined {
if (model._staticPropertyData[name]) return model._staticPropertyData[name];
const store = options?.asDynamic ? model._dynamicPropertyData : model._staticPropertyData;
if (store[name]) return store[name];
if (model.customProperties.has(descriptor)) return;
const obtain = formatRegistry.get(model.sourceData.kind);
if (!obtain) return;
model._staticPropertyData[name] = obtain(model);
store[name] = obtain(model);
model.customProperties.add(descriptor);
return model._staticPropertyData[name];
return store[name];
},
set(model: Model, value: T) {
model._staticPropertyData[name] = value;
if (options?.asDynamic) {
model._dynamicPropertyData[name] = value;
} else {
model._staticPropertyData[name] = value;
}
},
delete(model: Model) {
delete model._staticPropertyData[name];
if (options?.asDynamic) {
delete model._dynamicPropertyData[name];
} else {
delete model._staticPropertyData[name];
}
}
};
}

View File

@@ -2,6 +2,7 @@
* Copyright (c) 2019-2022 Mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { CustomPropertyDescriptor } from '../../../../mol-model/custom-property';
@@ -42,7 +43,7 @@ export namespace IndexPairBonds {
name: 'index_pair_bonds',
};
export const Provider = FormatPropertyProvider.create<IndexPairBonds>(Descriptor);
export const Provider = FormatPropertyProvider.create<IndexPairBonds>(Descriptor, { asDynamic: true });
export type Data = {
pairs: {

View File

@@ -11,30 +11,43 @@ import { Model } from '../../mol-model/structure';
import { StructureElement } from '../../mol-model/structure/structure';
import { CustomModelProperty } from '../common/custom-model-property';
export { BestDatabaseSequenceMapping };
export { SIFTSMapping as SIFTSMapping };
interface BestDatabaseSequenceMapping {
interface SIFTSMappingMapping {
readonly dbName: string[],
readonly accession: string[],
readonly num: number[],
readonly num: string[],
readonly residue: string[]
}
namespace BestDatabaseSequenceMapping {
export const Provider: CustomModelProperty.Provider<{}, BestDatabaseSequenceMapping> = CustomModelProperty.createProvider({
label: 'Best Database Sequence Mapping',
namespace SIFTSMapping {
export const Provider: CustomModelProperty.Provider<{}, SIFTSMappingMapping> = CustomModelProperty.createProvider({
label: 'SIFTS Mapping',
descriptor: CustomPropertyDescriptor({
name: 'molstar_best_database_sequence_mapping'
name: 'sifts_sequence_mapping'
}),
type: 'static',
defaultParams: {},
getParams: () => ({}),
isApplicable: (data: Model) => MmcifFormat.is(data.sourceData) && data.sourceData.data.frame.categories?.atom_site?.fieldNames.indexOf('pdbx_sifts_xref_db_name') >= 0,
isApplicable: (data: Model) => isAvailable(data),
obtain: async (ctx, data) => {
return { value: fromCif(data) };
}
});
export function isAvailable(model: Model) {
if (!MmcifFormat.is(model.sourceData)) return false;
const {
pdbx_sifts_xref_db_name: db_name,
pdbx_sifts_xref_db_acc: db_acc,
pdbx_sifts_xref_db_num: db_num,
pdbx_sifts_xref_db_res: db_res
} = model.sourceData.data.db.atom_site;
return db_name.isDefined && db_acc.isDefined && db_num.isDefined && db_res.isDefined;
}
export function getKey(loc: StructureElement.Location) {
const model = loc.unit.model;
const data = Provider.get(model).value;
@@ -55,22 +68,23 @@ namespace BestDatabaseSequenceMapping {
return `${dbName} ${data.accession[rI]} ${data.num[rI]} ${data.residue[rI]}`;
}
function fromCif(model: Model): BestDatabaseSequenceMapping | undefined {
function fromCif(model: Model): SIFTSMappingMapping | undefined {
if (!MmcifFormat.is(model.sourceData)) return;
const { atom_site } = model.sourceData.data.frame.categories;
const db_name = atom_site.getField('pdbx_sifts_xref_db_name');
const db_acc = atom_site.getField('pdbx_sifts_xref_db_acc');
const db_num = atom_site.getField('pdbx_sifts_xref_db_num');
const db_res = atom_site.getField('pdbx_sifts_xref_db_res');
const {
pdbx_sifts_xref_db_name: db_name,
pdbx_sifts_xref_db_acc: db_acc,
pdbx_sifts_xref_db_num: db_num,
pdbx_sifts_xref_db_res: db_res
} = model.sourceData.data.db.atom_site;
if (!db_name || !db_acc || !db_num || !db_res) return;
if (!db_name.isDefined || !db_acc.isDefined || !db_num.isDefined || !db_res.isDefined) return;
const { atomSourceIndex } = model.atomicHierarchy;
const { count, offsets: residueOffsets } = model.atomicHierarchy.residueAtomSegments;
const dbName = new Array<string>(count);
const accession = new Array<string>(count);
const num = new Array<number>(count);
const num = new Array<string>(count);
const residue = new Array<string>(count);
for (let i = 0; i < count; i++) {
@@ -79,15 +93,15 @@ namespace BestDatabaseSequenceMapping {
if (db_name.valueKind(row) !== Column.ValueKind.Present) {
dbName[i] = '';
accession[i] = '';
num[i] = 0;
num[i] = '';
residue[i] = '';
continue;
}
dbName[i] = db_name.str(row);
accession[i] = db_acc.str(row);
num[i] = db_num.int(row);
residue[i] = db_res.str(row);
dbName[i] = db_name.value(row);
accession[i] = db_acc.value(row);
num[i] = db_num.value(row);
residue[i] = db_res.value(row);
}
return { dbName, accession, num, residue };

View File

@@ -12,27 +12,27 @@ import { Color } from '../../../mol-util/color';
import { getPalette, getPaletteParams } from '../../../mol-util/color/palette';
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
import { CustomProperty } from '../../common/custom-property';
import { BestDatabaseSequenceMapping } from '../best-database-mapping';
import { SIFTSMapping } from '../sifts-mapping';
const DefaultColor = Color(0xFAFAFA);
const Description = 'Assigns a color based on best dababase sequence mapping.';
const Description = 'Assigns a color based on SIFTS mapping.';
// same colors for same accessions
const globalAccessionMap = new Map<string, number>();
export const BestDatabaseSequenceMappingColorThemeParams = {
export const SIFTSMappingColorThemeParams = {
...getPaletteParams({ type: 'colors', colorList: 'set-1' }),
};
export type BestDatabaseSequenceMappingColorThemeParams = typeof BestDatabaseSequenceMappingColorThemeParams
export function getBestDatabaseSequenceMappingColorThemeParams(ctx: ThemeDataContext) {
return BestDatabaseSequenceMappingColorThemeParams; // TODO return copy
export type SIFTSMappingColorThemeParams = typeof SIFTSMappingColorThemeParams
export function getSIFTSMappingColorThemeParams(ctx: ThemeDataContext) {
return SIFTSMappingColorThemeParams; // TODO return copy
}
export function BestDatabaseSequenceMappingColorTheme(ctx: ThemeDataContext, props: PD.Values<BestDatabaseSequenceMappingColorThemeParams>): ColorTheme<BestDatabaseSequenceMappingColorThemeParams> {
export function SIFTSMappingColorTheme(ctx: ThemeDataContext, props: PD.Values<SIFTSMappingColorThemeParams>): ColorTheme<SIFTSMappingColorThemeParams> {
let color: LocationColor;
if (ctx.structure) {
for (const m of ctx.structure.models) {
const mapping = BestDatabaseSequenceMapping.Provider.get(m).value;
const mapping = SIFTSMapping.Provider.get(m).value;
if (!mapping) continue;
for (const acc of mapping.accession) {
if (!acc || globalAccessionMap.has(acc)) continue;
@@ -45,7 +45,7 @@ export function BestDatabaseSequenceMappingColorTheme(ctx: ThemeDataContext, pro
const colorMap = new Map<string, Color>();
const getColor = (location: StructureElement.Location) => {
const key = BestDatabaseSequenceMapping.getKey(location);
const key = SIFTSMapping.getKey(location);
if (!key) return DefaultColor;
if (colorMap.has(key)) return colorMap.get(key)!;
@@ -70,7 +70,7 @@ export function BestDatabaseSequenceMappingColorTheme(ctx: ThemeDataContext, pro
}
return {
factory: BestDatabaseSequenceMappingColorTheme,
factory: SIFTSMappingColorTheme,
granularity: 'group',
preferSmoothing: true,
color,
@@ -79,26 +79,26 @@ export function BestDatabaseSequenceMappingColorTheme(ctx: ThemeDataContext, pro
};
}
export const BestDatabaseSequenceMappingColorThemeProvider: ColorTheme.Provider<BestDatabaseSequenceMappingColorThemeParams, 'best-sequence-database-mapping'> = {
name: 'best-sequence-database-mapping',
label: 'Best Database Sequence Mapping',
export const SIFTSMappingColorThemeProvider: ColorTheme.Provider<SIFTSMappingColorThemeParams, 'sifts-mapping'> = {
name: 'sifts-mapping',
label: 'SIFTS Mapping',
category: ColorTheme.Category.Residue,
factory: BestDatabaseSequenceMappingColorTheme,
getParams: getBestDatabaseSequenceMappingColorThemeParams,
defaultValues: PD.getDefaultValues(BestDatabaseSequenceMappingColorThemeParams),
isApplicable: (ctx: ThemeDataContext) => !!ctx.structure?.models.some(m => BestDatabaseSequenceMapping.Provider.isApplicable(m)),
factory: SIFTSMappingColorTheme,
getParams: getSIFTSMappingColorThemeParams,
defaultValues: PD.getDefaultValues(SIFTSMappingColorThemeParams),
isApplicable: (ctx: ThemeDataContext) => !!ctx.structure?.models.some(m => SIFTSMapping.Provider.isApplicable(m)),
ensureCustomProperties: {
attach: async (ctx: CustomProperty.Context, data: ThemeDataContext) => {
if (!data.structure) return;
for (const m of data.structure.models) {
await BestDatabaseSequenceMapping.Provider.attach(ctx, m, void 0, true);
await SIFTSMapping.Provider.attach(ctx, m, void 0, true);
}
},
detach: (data) => {
if (!data.structure) return;
for (const m of data.structure.models) {
BestDatabaseSequenceMapping.Provider.ref(m, false);
SIFTSMapping.Provider.ref(m, false);
}
}
}

View File

@@ -5,7 +5,11 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Column } from '../../../../mol-data/db';
import { mmCIF_Database } from '../../../../mol-io/reader/cif/schema/mmcif';
import { CifWriter } from '../../../../mol-io/writer/cif';
import { MmcifFormat } from '../../../../mol-model-formats/structure/mmcif';
import { SIFTSMapping } from '../../../../mol-model-props/sequence/sifts-mapping';
import { StructureElement, Structure, StructureProperties as P } from '../../structure';
import { CifExportContext } from '../mmcif';
import CifField = CifWriter.Field
@@ -26,7 +30,64 @@ function atom_site_auth_asym_id(e: StructureElement.Location) {
return l + suffix;
}
const atom_site_fields = () => CifWriter.fields<StructureElement.Location, Structure>()
const atom_site_pdbx_label_index = {
shouldInclude(s: AtomSiteData) {
return !!s.atom_site?.pdbx_label_index.isDefined;
},
value(e: StructureElement.Location, d: AtomSiteData) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_label_index.value(srcIndex);
},
};
const SIFTS = {
shouldInclude(s: AtomSiteData) {
return SIFTSMapping.isAvailable(s.structure.models[0]);
},
pdbx_sifts_xref_db_name: {
value(e: StructureElement.Location, d: AtomSiteData) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_name.value(srcIndex);
},
valueKind(e: StructureElement.Location, d: any) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_name.valueKind(srcIndex);
},
},
pdbx_sifts_xref_db_acc: {
value(e: StructureElement.Location, d: AtomSiteData) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_acc.value(srcIndex);
},
valueKind(e: StructureElement.Location, d: any) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_acc.valueKind(srcIndex);
},
},
pdbx_sifts_xref_db_num: {
value(e: StructureElement.Location, d: AtomSiteData) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_num.value(srcIndex);
},
valueKind(e: StructureElement.Location, d: any) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_num.valueKind(srcIndex);
},
},
pdbx_sifts_xref_db_res: {
value(e: StructureElement.Location, d: AtomSiteData) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_res.value(srcIndex);
},
valueKind(e: StructureElement.Location, d: any) {
const srcIndex = d.sourceIndex.value(e.element);
return d.atom_site!.pdbx_sifts_xref_db_res.valueKind(srcIndex);
},
}
};
const atom_site_fields = () => CifWriter.fields<StructureElement.Location, AtomSiteData>()
.str('group_PDB', P.residue.group_PDB)
.index('id')
.str('type_symbol', P.atom.type_symbol as any)
@@ -62,18 +123,37 @@ const atom_site_fields = () => CifWriter.fields<StructureElement.Location, Struc
.str('auth_asym_id', atom_site_auth_asym_id)
.int('pdbx_PDB_model_num', P.unit.model_num, { encoder: E.deltaRLE })
.int('pdbx_label_index', atom_site_pdbx_label_index.value, { shouldInclude: atom_site_pdbx_label_index.shouldInclude })
// SIFTS
.str('pdbx_sifts_xref_db_name', SIFTS.pdbx_sifts_xref_db_name.value, { shouldInclude: SIFTS.shouldInclude, valueKind: SIFTS.pdbx_sifts_xref_db_name.valueKind })
.str('pdbx_sifts_xref_db_acc', SIFTS.pdbx_sifts_xref_db_acc.value, { shouldInclude: SIFTS.shouldInclude, valueKind: SIFTS.pdbx_sifts_xref_db_acc.valueKind })
.str('pdbx_sifts_xref_db_num', SIFTS.pdbx_sifts_xref_db_num.value, { shouldInclude: SIFTS.shouldInclude, valueKind: SIFTS.pdbx_sifts_xref_db_num.valueKind })
.str('pdbx_sifts_xref_db_res', SIFTS.pdbx_sifts_xref_db_res.value, { shouldInclude: SIFTS.shouldInclude, valueKind: SIFTS.pdbx_sifts_xref_db_res.valueKind })
// .str('operator_name', P.unit.operator_name, {
// shouldInclude: structure => structure.units.some(u => !u.conformation.operator.isIdentity)
// })
.getFields();
interface AtomSiteData {
structure: Structure,
sourceIndex: Column<number>,
atom_site?: mmCIF_Database['atom_site']
}
export const _atom_site: CifCategory<CifExportContext> = {
name: 'atom_site',
instance({ structures }: CifExportContext) {
return {
fields: atom_site_fields(),
source: structures.map(s => ({
data: s,
data: {
structure: s,
sourceIndex: s.model.atomicHierarchy.atomSourceIndex,
atom_site: MmcifFormat.is(s.model.sourceData) ? s.model.sourceData.data.db.atom_site : void 0
} as AtomSiteData,
rowCount: s.elementCount,
keys: () => s.elementLocations()
}))

View File

@@ -1,28 +1,34 @@
/**
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2021-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
* @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
*/
import { Segmentation } from '../../../../mol-data/int';
import { Mat4 } from '../../../../mol-math/linear-algebra';
import { MinimizeRmsd } from '../../../../mol-math/linear-algebra/3d/minimize-rmsd';
import { BestDatabaseSequenceMapping } from '../../../../mol-model-props/sequence/best-database-mapping';
import { SIFTSMapping } from '../../../../mol-model-props/sequence/sifts-mapping';
import { ElementIndex } from '../../model/indexing';
import { Structure } from '../structure';
import { Unit } from '../unit';
export interface AlignmentResult {
export interface AlignmentResultEntry {
transform: MinimizeRmsd.Result,
pivot: number,
other: number
}
export function alignAndSuperposeWithBestDatabaseMapping(structures: Structure[]): AlignmentResult[] {
export interface AlignmentResult {
entries: AlignmentResultEntry[],
zeroOverlapPairs: [number, number][],
failedPairs: [number, number][]
}
export function alignAndSuperposeWithSIFTSMapping(structures: Structure[], options?: { traceOnly?: boolean }): AlignmentResult {
const indexMap = new Map<string, IndexEntry>();
for (let i = 0; i < structures.length; i++) {
buildIndex(structures[i], indexMap, i);
buildIndex(structures[i], indexMap, i, options?.traceOnly ?? true);
}
const index = Array.from(indexMap.values());
@@ -30,15 +36,26 @@ export function alignAndSuperposeWithBestDatabaseMapping(structures: Structure[]
// TODO: support non-first structure pivots
const pairs = findPairs(structures.length, index);
const ret: AlignmentResult[] = [];
const zeroOverlapPairs: AlignmentResult['zeroOverlapPairs'] = [];
const failedPairs: AlignmentResult['failedPairs'] = [];
const entries: AlignmentResultEntry[] = [];
for (const p of pairs) {
const [a, b] = getPositionTables(index, p.i, p.j, p.count);
const transform = MinimizeRmsd.compute({ a, b });
console.log(Mat4.makeTable(transform.bTransform), transform.rmsd);
ret.push({ transform, pivot: p.i, other: p.j });
if (p.count === 0) {
zeroOverlapPairs.push([p.i, p.j]);
} else {
const [a, b] = getPositionTables(index, p.i, p.j, p.count);
const transform = MinimizeRmsd.compute({ a, b });
if (Number.isNaN(transform.rmsd)) {
failedPairs.push([p.i, p.j]);
} else {
entries.push({ transform, pivot: p.i, other: p.j });
}
}
}
return ret;
return { entries, zeroOverlapPairs, failedPairs };
}
function getPositionTables(index: IndexEntry[], pivot: number, other: number, N: number) {
@@ -53,7 +70,6 @@ function getPositionTables(index: IndexEntry[], pivot: number, other: number, N:
const l = Math.min(a[2] - a[1], b[2] - b[1]);
// TODO: allow to use just backbone atoms?
// TODO: check if residue types match?
for (let i = 0; i < l; i++) {
let eI = (a[1] + i) as ElementIndex;
@@ -121,19 +137,20 @@ interface IndexEntry {
pivots: { [i: number]: [unit: Unit.Atomic, start: ElementIndex, end: ElementIndex] | undefined }
}
function buildIndex(structure: Structure, index: Map<string, IndexEntry>, sI: number) {
function buildIndex(structure: Structure, index: Map<string, IndexEntry>, sI: number, traceOnly: boolean) {
for (const unit of structure.units) {
if (unit.kind !== Unit.Kind.Atomic) continue;
const { elements, model } = unit;
const map = BestDatabaseSequenceMapping.Provider.get(model).value;
const map = SIFTSMapping.Provider.get(model).value;
if (!map) return;
const { dbName, accession, num } = map;
const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainAtomSegments, elements);
const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, elements);
const traceElementIndex = unit.model.atomicHierarchy.derived.residue.traceElementIndex;
while (chainsIt.hasNext) {
const chainSegment = chainsIt.move();
@@ -144,8 +161,15 @@ function buildIndex(structure: Structure, index: Map<string, IndexEntry>, sI: nu
if (!dbName[rI]) continue;
const start = elements[residueSegment.start];
const end = elements[residueSegment.end - 1] + 1 as ElementIndex;
let start, end;
if (traceOnly) {
start = traceElementIndex[rI];
if (start === -1) continue;
end = start + 1 as ElementIndex;
} else {
start = elements[residueSegment.start];
end = elements[residueSegment.end - 1] + 1 as ElementIndex;
}
const key = `${dbName[rI]}-${accession[rI]}-${num[rI]}`;
@@ -161,6 +185,4 @@ function buildIndex(structure: Structure, index: Map<string, IndexEntry>, sI: nu
}
}
}
console.log(index);
}

View File

@@ -1,7 +1,8 @@
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
*/
import { CollapsableControls, PurePluginUIComponent } from '../base';
@@ -20,9 +21,9 @@ import { ParameterControls } from '../controls/parameters';
import { stripTags } from '../../mol-util/string';
import { StructureSelectionHistoryEntry } from '../../mol-plugin-state/manager/structure/selection';
import { ToggleSelectionModeButton } from './selection';
import { alignAndSuperposeWithBestDatabaseMapping } from '../../mol-model/structure/structure/util/superposition-db-mapping';
import { alignAndSuperposeWithSIFTSMapping } from '../../mol-model/structure/structure/util/superposition-sifts-mapping';
import { PluginCommands } from '../../mol-plugin/commands';
import { BestDatabaseSequenceMapping } from '../../mol-model-props/sequence/best-database-mapping';
import { SIFTSMapping } from '../../mol-model-props/sequence/sifts-mapping';
export class StructureSuperpositionControls extends CollapsableControls {
defaultState() {
@@ -48,7 +49,8 @@ export class StructureSuperpositionControls extends CollapsableControls {
}
export const StructureSuperpositionParams = {
alignSequences: PD.Boolean(true, { isEssential: true, description: 'Perform a sequence alignment and use the aligned residue pairs to guide the 3D superposition.' }),
alignSequences: PD.Boolean(true, { isEssential: true, description: 'For Chain-based 3D superposition, perform a sequence alignment and use the aligned residue pairs to guide the 3D superposition.' }),
traceOnly: PD.Boolean(true, { description: 'For Chain- and Uniprot-based 3D superposition, base superposition only on CA (and equivalent) atoms.' })
};
const DefaultStructureSuperpositionOptions = PD.getDefaultValues(StructureSuperpositionParams);
export type StructureSuperpositionOptions = PD.ValuesFor<typeof StructureSuperpositionParams>
@@ -94,7 +96,7 @@ export class SuperpositionControls extends PurePluginUIComponent<{ }, Superposit
});
this.subscribe(this.plugin.managers.structure.hierarchy.behaviors.selection, sel => {
this.setState({ canUseDb: sel.structures.every(s => !!s.cell.obj?.data && s.cell.obj.data.models.some(m => BestDatabaseSequenceMapping.Provider.isApplicable(m))) });
this.setState({ canUseDb: sel.structures.every(s => !!s.cell.obj?.data && s.cell.obj.data.models.some(m => SIFTSMapping.Provider.isApplicable(m))) });
});
}
@@ -123,10 +125,10 @@ export class SuperpositionControls extends PurePluginUIComponent<{ }, Superposit
}
superposeChains = async () => {
const { query } = StructureSelectionQueries.trace;
const { query } = this.state.options.traceOnly ? StructureSelectionQueries.trace : StructureSelectionQueries.polymer;
const entries = this.chainEntries;
const traceLocis = entries.map((e, i) => {
const locis = entries.map((e, i) => {
const s = StructureElement.Loci.toStructure(e.loci);
const loci = StructureSelection.toLociWithSourceUnits(query(new QueryContext(s)));
return StructureElement.Loci.remap(loci, i === 0
@@ -136,11 +138,11 @@ export class SuperpositionControls extends PurePluginUIComponent<{ }, Superposit
});
const transforms = this.state.options.alignSequences
? alignAndSuperpose(traceLocis)
: superpose(traceLocis);
? alignAndSuperpose(locis)
: superpose(locis);
const eA = entries[0];
for (let i = 1, il = traceLocis.length; i < il; ++i) {
for (let i = 1, il = locis.length; i < il; ++i) {
const eB = entries[i];
const { bTransform, rmsd } = transforms[i - 1];
await this.transform(eB.cell, bTransform);
@@ -148,6 +150,7 @@ export class SuperpositionControls extends PurePluginUIComponent<{ }, Superposit
const labelB = stripTags(eB.label);
this.plugin.log.info(`Superposed [${labelA}] and [${labelB}] with RMSD ${rmsd.toFixed(2)}.`);
}
await this.cameraReset();
};
superposeAtoms = async () => {
@@ -171,26 +174,47 @@ export class SuperpositionControls extends PurePluginUIComponent<{ }, Superposit
const count = entries[i].atoms.length;
this.plugin.log.info(`Superposed ${count} ${count === 1 ? 'atom' : 'atoms'} of [${labelA}] and [${labelB}] with RMSD ${rmsd.toFixed(2)}.`);
}
await this.cameraReset();
};
superposeDb = async () => {
const input = this.plugin.managers.structure.hierarchy.behaviors.selection.value.structures;
const traceOnly = this.state.options.traceOnly;
const transforms = alignAndSuperposeWithBestDatabaseMapping(input.map(s => s.cell.obj?.data!));
const structures = input.map(s => s.cell.obj?.data!);
const { entries, failedPairs, zeroOverlapPairs } = alignAndSuperposeWithSIFTSMapping(structures, { traceOnly });
let rmsd = 0;
for (const xform of transforms) {
for (const xform of entries) {
await this.transform(input[xform.other].cell, xform.transform.bTransform);
rmsd += xform.transform.rmsd;
}
rmsd /= Math.max(transforms.length - 1, 1);
rmsd /= Math.max(entries.length - 1, 1);
this.plugin.log.info(`Superposed ${input.length} structures with avg. RMSD ${rmsd.toFixed(2)} Å.`);
const formatPairs = (pairs: [number, number][]) => {
return `[${pairs.map(([i, j]) => `(${structures[i].models[0].entryId}, ${structures[j].models[0].entryId})`).join(', ')}]`;
};
if (zeroOverlapPairs.length) {
this.plugin.log.warn(`Superposition: No UNIPROT mapping overlap between structures ${formatPairs(zeroOverlapPairs)}.`);
}
if (failedPairs.length) {
this.plugin.log.error(`Superposition: Failed to superpose structures ${formatPairs(failedPairs)}.`);
}
if (entries.length) {
this.plugin.log.info(`Superposed ${entries.length + 1} structures with avg. RMSD ${rmsd.toFixed(2)} Å.`);
await this.cameraReset();
}
};
async cameraReset() {
await new Promise(res => requestAnimationFrame(res));
PluginCommands.Camera.Reset(this.plugin);
};
}
toggleByChains = () => this.setState({ action: this.state.action === 'byChains' ? void 0 : 'byChains' });
toggleByAtoms = () => this.setState({ action: this.state.action === 'byAtoms' ? void 0 : 'byAtoms' });
@@ -323,8 +347,8 @@ export class SuperpositionControls extends PurePluginUIComponent<{ }, Superposit
superposeByDbMapping() {
return <>
<Button icon={SuperposeChainsSvg} title='Superpose structures using database mapping.' className='msp-btn msp-btn-block' onClick={this.superposeDb} style={{ marginTop: '1px' }} disabled={this.state.isBusy}>
DB
<Button icon={SuperposeChainsSvg} title='Superpose structures using intersection of residues from SIFTS UNIPROT mapping.' className='msp-btn msp-btn-block' onClick={this.superposeDb} style={{ marginTop: '1px' }} disabled={this.state.isBusy}>
Uniprot
</Button>
</>;
}

View File

@@ -11,6 +11,6 @@ export { AccessibleSurfaceArea } from './custom-props/computed/accessible-surfac
export { Interactions } from './custom-props/computed/interactions';
export { SecondaryStructure } from './custom-props/computed/secondary-structure';
export { ValenceModel } from './custom-props/computed/valence-model';
export { BestDatabaseSequenceMapping } from './custom-props/sequence/best-database-mapping';
export { SIFTSMapping as BestDatabaseSequenceMapping } from './custom-props/sequence/sifts-mapping';
export { CrossLinkRestraint } from './custom-props/integrative/cross-link-restraint';

View File

@@ -5,17 +5,17 @@
*/
import { OrderedSet } from '../../../../../mol-data/int';
import { BestDatabaseSequenceMapping as BestDatabaseSequenceMappingProp } from '../../../../../mol-model-props/sequence/best-database-mapping';
import { BestDatabaseSequenceMappingColorThemeProvider } from '../../../../../mol-model-props/sequence/themes/best-database-mapping';
import { SIFTSMapping as BestDatabaseSequenceMappingProp } from '../../../../../mol-model-props/sequence/sifts-mapping';
import { SIFTSMappingColorThemeProvider } from '../../../../../mol-model-props/sequence/themes/sifts-mapping';
import { Loci } from '../../../../../mol-model/loci';
import { StructureElement } from '../../../../../mol-model/structure';
import { ParamDefinition as PD } from '../../../../../mol-util/param-definition';
import { PluginBehavior } from '../../../behavior';
export const BestDatabaseSequenceMapping = PluginBehavior.create<{ autoAttach: boolean, showTooltip: boolean }>({
name: 'best-sequence-database-mapping-prop',
export const SIFTSMapping = PluginBehavior.create<{ autoAttach: boolean, showTooltip: boolean }>({
name: 'sifts-mapping-prop',
category: 'custom-props',
display: { name: 'Best Database Sequence Mapping' },
display: { name: 'SIFTS Mapping' },
ctor: class extends PluginBehavior.Handler<{ autoAttach: boolean, showTooltip: boolean }> {
private provider = BestDatabaseSequenceMappingProp.Provider;
@@ -39,13 +39,13 @@ export const BestDatabaseSequenceMapping = PluginBehavior.create<{ autoAttach: b
register(): void {
this.ctx.customModelProperties.register(this.provider, this.params.autoAttach);
this.ctx.representation.structure.themes.colorThemeRegistry.add(BestDatabaseSequenceMappingColorThemeProvider);
this.ctx.representation.structure.themes.colorThemeRegistry.add(SIFTSMappingColorThemeProvider);
this.ctx.managers.lociLabels.addProvider(this.labelProvider);
}
unregister() {
this.ctx.customModelProperties.unregister(this.provider.descriptor.name);
this.ctx.representation.structure.themes.colorThemeRegistry.remove(BestDatabaseSequenceMappingColorThemeProvider);
this.ctx.representation.structure.themes.colorThemeRegistry.remove(SIFTSMappingColorThemeProvider);
this.ctx.managers.lociLabels.removeProvider(this.labelProvider);
}
},