|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2019-2021 Mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2019-2022 Mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
*/
|
|
@@ -10,9 +10,9 @@ import { Column } from '../../../../mol-data/db';
|
|
|
import { FormatPropertyProvider } from '../../common/property';
|
|
|
import { BondType } from '../../../../mol-model/structure/model/types';
|
|
|
import { ElementIndex } from '../../../../mol-model/structure';
|
|
|
-import { DefaultBondMaxRadius } from '../../../../mol-model/structure/structure/unit/bonds/common';
|
|
|
|
|
|
export type IndexPairsProps = {
|
|
|
+ readonly id: ArrayLike<number>
|
|
|
readonly order: ArrayLike<number>
|
|
|
readonly distance: ArrayLike<number>
|
|
|
readonly flag: ArrayLike<BondType.Flag>
|
|
@@ -22,17 +22,19 @@ export type IndexPairBonds = { bonds: IndexPairs, maxDistance: number }
|
|
|
|
|
|
function getGraph(indexA: ArrayLike<ElementIndex>, indexB: ArrayLike<ElementIndex>, props: Partial<IndexPairsProps>, count: number): IndexPairs {
|
|
|
const builder = new IntAdjacencyGraph.EdgeBuilder(count, indexA, indexB);
|
|
|
+ const id = new Int32Array(builder.slotCount);
|
|
|
const order = new Int8Array(builder.slotCount);
|
|
|
const distance = new Array(builder.slotCount);
|
|
|
const flag = new Array(builder.slotCount);
|
|
|
for (let i = 0, _i = builder.edgeCount; i < _i; i++) {
|
|
|
builder.addNextEdge();
|
|
|
+ builder.assignProperty(id, props.id ? props.id[i] : -1);
|
|
|
builder.assignProperty(order, props.order ? props.order[i] : 1);
|
|
|
builder.assignProperty(distance, props.distance ? props.distance[i] : -1);
|
|
|
builder.assignProperty(flag, props.flag ? props.flag[i] : BondType.Flag.Covalent);
|
|
|
}
|
|
|
|
|
|
- return builder.createGraph({ order, distance, flag });
|
|
|
+ return builder.createGraph({ id, order, distance, flag });
|
|
|
}
|
|
|
|
|
|
export namespace IndexPairBonds {
|
|
@@ -45,15 +47,29 @@ export namespace IndexPairBonds {
|
|
|
export type Data = {
|
|
|
pairs: {
|
|
|
indexA: Column<number>,
|
|
|
- indexB: Column<number>
|
|
|
+ indexB: Column<number>,
|
|
|
+ id?: Column<number>,
|
|
|
order?: Column<number>,
|
|
|
+ /**
|
|
|
+ * Useful for bonds in periodic cells. That is, only bonds within the given
|
|
|
+ * distance are added. This allows for bond between periodic image but
|
|
|
+ * avoids unwanted bonds with wrong distances.
|
|
|
+ */
|
|
|
distance?: Column<number>,
|
|
|
flag?: Column<BondType.Flag>,
|
|
|
},
|
|
|
count: number
|
|
|
}
|
|
|
|
|
|
- export const DefaultProps = { maxDistance: DefaultBondMaxRadius };
|
|
|
+ export const DefaultProps = {
|
|
|
+ /**
|
|
|
+ * If -1, test using element-based threshold, otherwise distance in Angstrom.
|
|
|
+ *
|
|
|
+ * This option exists to handle bonds in periodic cells. For systems that are
|
|
|
+ * made from beads (as opposed to atomic elements), set to a spicific distance.
|
|
|
+ */
|
|
|
+ maxDistance: -1
|
|
|
+ };
|
|
|
export type Props = typeof DefaultProps
|
|
|
|
|
|
export function fromData(data: Data, props: Partial<Props> = {}): IndexPairBonds {
|
|
@@ -61,11 +77,12 @@ export namespace IndexPairBonds {
|
|
|
const { pairs, count } = data;
|
|
|
const indexA = pairs.indexA.toArray() as ArrayLike<ElementIndex>;
|
|
|
const indexB = pairs.indexB.toArray() as ArrayLike<ElementIndex>;
|
|
|
+ const id = pairs.id && pairs.id.toArray();
|
|
|
const order = pairs.order && pairs.order.toArray();
|
|
|
const distance = pairs.distance && pairs.distance.toArray();
|
|
|
const flag = pairs.flag && pairs.flag.toArray();
|
|
|
return {
|
|
|
- bonds: getGraph(indexA, indexB, { order, distance, flag }, count),
|
|
|
+ bonds: getGraph(indexA, indexB, { id, order, distance, flag }, count),
|
|
|
maxDistance: p.maxDistance
|
|
|
};
|
|
|
}
|