Published
Edited
May 4, 2022
3 forks
Insert cell
Insert cell
Insert cell
pixelSize = 0.2208
Insert cell
minChainLength = 4
Insert cell
Insert cell
Insert cell
dataForDistancesBetweenChains = angles.results
.filter(d => {
return d.chain1.chain.length > minChainLength && d.chain2.chain.length > minChainLength
})
.map(d => {
return {
distNm: d.dist*pixelSize,
reg: d.carbIndex,
innerConcentration: d.innerConcentration,
}
})
Insert cell
meanDistance = math.mean(dataForDistancesBetweenChains.filter(d => d.distNm < 15.3).map(d => d.distNm))
Insert cell
stdDistance = math.std(dataForDistancesBetweenChains.filter(d => d.distNm < 15.3).map(d => d.distNm))
Insert cell
Insert cell
dataForNextRubInChain = angles.distWithinChain.filter(d => d.length > 2).flat()
.map(d => {
return {
distNm: d.d*pixelSize,
reg: d.carbIndex,
innerConcentration: d.innerConcentration,
}
})
Insert cell
params = {
return {
minNumberOfChains: 1,
minChainSize: 1,
maxDistance: 70
}
}
Insert cell
Insert cell
FileAttachment("insetAngleBetweenChains.svg").image()
Insert cell
Insert cell
Insert cell
dataForAngleBetweenNeighbChains = angles.results
.filter(d => {
return d.chain1.chain.length > 3 && d.chain2.chain.length > 3
})
.filter( d => d.dist < params.maxDistance )
.map(d => {
return {
angle: d.angle,
reg: d.carbIndex,
innerConcentration: d.innerConcentration,
}
})
Insert cell
meanAngleBetweenChain = math.mean(dataForAngleBetweenNeighbChains.filter(d => d.angle < 24).map(d => d.angle))
Insert cell
stdAngleBetweenChain = math.std(dataForAngleBetweenNeighbChains.filter(d => d.angle < 24).map(d => d.angle))
Insert cell
Insert cell
Insert cell
meanTwist = math.mean(dataForTwistBetweenNeighbRubsWithinChain.map(d => d.twist))
Insert cell
stdTwist = math.std(dataForTwistBetweenNeighbRubsWithinChain.map(d => d.twist))
Insert cell
Insert cell
Insert cell
Insert cell
meanBend = math.mean(dataForBendingBetweenNeighbRubsWithinChain.map(d => d.bend))
Insert cell
stdBend = math.std(dataForBendingBetweenNeighbRubsWithinChain.map(d => d.bend))
Insert cell
Insert cell
Insert cell
pairsOfRubWithBendAndTwist = rubPair.filter(d => d.center !== null)
Insert cell
rubPair = {
const results = []
const pairs = angles.distWithinChain.flat()
for (const pair of pairs) {
const rub1AsRef = math.norm(math.subtract(pair.rub2.pos, math.add(pair.rub1.pos, math.dotMultiply(pair.rub1.vec, 45))))
const rub2AsRef = math.norm(math.subtract(pair.rub1.pos, math.add(pair.rub2.pos, math.dotMultiply(pair.rub2.vec, 45))))
if (rub1AsRef < 22.5) {
results.push({
center: pair.rub1.tag,
bend: pair.bend,
twist: pair.twist,
above: pair.rub2.tag
})
} else if (rub2AsRef < 22.5) {
results.push({
center: pair.rub2.tag,
bend: pair.bend,
twist: pair.twist,
above: pair.rub1.tag
})
} else {
results.push({
center: null,
bend: null,
twist: null,
above: null
})
}
}
return results
}
Insert cell
twistedAngs.filter(d => d.t1 === 1713 || d.t2 === 1713)
Insert cell
twistedAngs = {
const result = []
angles.twistedAngles.filter(d => d.length > 3).forEach((twist, chainId) => {
for (let i = 0; i < twist.length - 1; i++) {
const dAngle = twist[i+1].narot - twist[i].narot
result.push(
{
original: {
a1: twist[i].originalNarot,
a2: twist[i+1].originalNarot,
},
t1: twist[i].tag,
t2: twist[i+1].tag,
a1: twist[i].narot,
a2: twist[i+1].narot,
...twist[i],
chainId,
dAngle: dAngle > 45 ? 90 - dAngle : (dAngle < -45 ? 90 + dAngle : dAngle)
}
)
}
})
return result
}
Insert cell
twistedAngs.filter(d => d.original.a2 < -400)
Insert cell
angles.twistedAngles.map(r => r.filter(d => d.carbIndex === 7)).filter(d => d.length )
Insert cell
angles = {
const results = []
const allDistances = []
const twistedAngles = []
const distWithinChain = []
for (const carbChains of chainData.results) {
const leadingVectors = leadingVector.filter(d => d.carbIndex === carbChains.carb.carbIndex)
const N = leadingVectors.length
if (N > params.minNumberOfChains) {
const rubs = allDataWithVectors.filter(d => d.reg === carbChains.carb.carbIndex)
for (let i = 0; i < N - 1; i++) {
const chain1 = leadingVectors[i].leadVector
const chain1Normed = math.dotDivide(chain1, math.norm(chain1))
const chainData = leadingVectors[i].chain
.map(d => rubs.find( r => r.tag === d))
.map(r => {
const pos = math.matrix([r.x, r.y, r.z])
const posUnit = math.dotDivide(pos, math.norm(pos))
const p = math.dot(pos, chain1Normed)
return {
...r,
p
}
})
.sort((a, b) => a.p - b.p)
.map(r => {
const narot = math.dot(chain1, r.vec) > 0 ? r.narot : -r.narot
return {
...carbChains.carb,
narot: narot < 0 ? (90 + (narot % 90) ) % 90 : narot % 90,
originalNarot: narot,
tag: r.tag,
p: r.p,
pos: math.matrix([r.x, r.y, r.z]),
vec: r.vec
}
})//
twistedAngles.push(chainData)
const distsInChain = []
for (let z = 0; z < chainData.length - 1; z++) {
const rub1Orientation = math.dotDivide(chainData[z].vec, math.norm(chainData[z].vec))
const rub2Orientation = math.dotDivide(chainData[z+1].vec, math.norm(chainData[z+1].vec))
const tmpBend = math.dot(rub1Orientation, rub2Orientation)
const bend = tmpBend > 0 ? tmpBend : math.dot(rub1Orientation, math.dotMultiply(rub2Orientation, -1))
const dAngle = chainData[z+1].narot - chainData[z].narot
distsInChain.push({
d: math.norm(math.subtract(chainData[z].pos, chainData[z+1].pos)),
rub1: chainData[z+1],
rub2: chainData[z],
bend: 180 * math.acos(bend) /Math.PI,
twist: dAngle > 45 ? 90 - dAngle : (dAngle < -45 ? 90 + dAngle : dAngle),
l: chainData.length,
...carbChains.carb
})
}
distWithinChain.push(distsInChain)

for (let j = i + 1; j < N; j++) {
const comDist = math.norm(math.subtract(leadingVectors[i].centerOfMass, leadingVectors[j].centerOfMass))
const distance = distBetweenChains(leadingVectors[i], leadingVectors[j])
distance.allDists.forEach(d => {
allDistances.push({
i: leadingVectors[i].chainId,
j: leadingVectors[j].chainId,
minDist: distance.dist,
dist: d
})
})
const chain2 = leadingVectors[j].leadVector
const chain2Contrary = math.dotMultiply(-1, chain2)

const chain2Normed = math.dotDivide(chain2, math.norm(chain2))
const chain2ContraryNormed = math.dotMultiply(-1, chain2Normed)
const dot1 = math.dot(chain1Normed, chain2Normed)
const dot2 = math.dot(chain1Normed, chain2ContraryNormed)
const c2 = dot1 > dot2 ? chain2Normed : chain2ContraryNormed
const dot = Math.max(dot1, dot2)
const cross = math.cross(chain1Normed, c2)
const theta = math.dot(cross, distance.direction)
results.push(
{
...carbChains.carb,
dot,
angle: 180 * math.acos(dot) /Math.PI,
comDist,
dist: distance.dist,
direction: distance.direction,
theta,
chainId1: leadingVectors[i].chainId,
chainId2: leadingVectors[j].chainId,
chain1: leadingVectors[i],
chain2: leadingVectors[j]
}
)
}
}
}
}
return { results, allDistances, twistedAngles, distWithinChain }
}
Insert cell
distBetweenChains(leadingVector[0], leadingVector[1])
Insert cell
angles
.twistedAngles
//.filter(d => d.i === 1062)
Insert cell
distBetweenChains = (chain1, chain2) => {
let dist = 1E9
let direction = math.zeros(3)
const allDists = []
for (const r1 of chain1.pos) {
for ( const r2 of chain2.pos) {
const sub = math.subtract(r1, r2)
const newDist = math.norm(sub)
allDists.push(newDist)
if (dist > newDist) {
dist = newDist
direction = sub
}
}
}
return { dist, direction, allDists }
}
Insert cell
leadingVector.filter(d => d.carbIndex === 59)
Insert cell
Insert cell
com3D(93)
Insert cell
com3D = (carbIndex) => {
const leadVectors = leadingVector.filter(d => d.carbIndex === carbIndex)
const com = leadVectors
.map(d => {
return {
pos: d.centerOfMass,
vec: d.leadVector
}
})//.map(d => {pos: [d.subset(math.index(0)), d.subset(math.index(1)), d.subset(math.index(2))], vec: d.leadVector })
return com
}
Insert cell
{
return math.matrix(math.zeros([3,3])).format()
}
Insert cell
31*31
Insert cell
chainData
Insert cell
allDataWithVectors
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
druid = require("@saehrimnir/druidjs@^0.3.7");
Insert cell
THREE = {
const THREE = window.THREE = await require("three");
await require("three/examples/js/controls/OrbitControls.js").catch(() => {});
return window.THREE;
}
Insert cell
Insert cell
Insert cell
mds2D(2)
Insert cell
mds2D = (carbIndex) => {
const leadingVectors = leadingVector.filter(d => d.carbIndex === carbIndex)
const N = leadingVectors.length
const result = []
const initial = math.zeros([N,N])
const M = math.zeros([N,N])
if (N > params.minNumberOfChains) {
for (let i = 0; i < N - 1; i++) {
const chain1 = leadingVectors[i]
for (let j = i + 1; j < N; j++) {
const chain2 = leadingVectors[j]
const d = distBetweenChains(chain1, chain2).dist
initial[i][j] = d
initial[j][i] = d
}
}
}
const X = druid.Matrix.from(initial)
const DR = druid['MDS']
const mdsData = (new DR(X)).transform()
const mds = []
for (const d of mdsData) {
mds.push({x: d[0], y: d[1]})
}
return mds
}
Insert cell
Insert cell
Insert cell
Insert cell
cms = drawCarb(7)
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more