data = {
const results = {
data: [],
error: [],
log: []
}
for (const rub of allDataWithVectors) {
const carbChain = chainData.results.find(d => d.carb.carbIndex === rub.reg)
const carbVol = carbVolumes.find(d => d.carbIndex === rub.reg)
let partners = new Array(10).fill(null)
const inChain = carbChain.s.chains.flat().includes(rub.tag) ? 1 : 0
const vecs = []
let above, below
let distAbove, distBelow = null
let nc = null
let lc = null
let innerChain = 0
const twists = [
null, null
]
const bends = [
null, null
]
if (inChain) {
const chain = carbChain.s.chains.find(d => d.includes(rub.tag))
const leadChain = leadingVector.find(c => c.chain.includes(rub.tag))
innerChain = innerChainData.find(d => d.chain.includes(rub.tag)) ? 1 : 0
chain.forEach((tag, i) => {
partners[i] = tag
const rp = allDataWithVectors.find(d => d.tag === tag)
if (!rp) {
console.log(tag)
}
const rpPos = math.matrix([rp.x, rp.y, rp.z])
const rubPos = math.matrix([rub.x, rub.y, rub.z])
const dVec = math.subtract(rpPos, rubPos)
const dot = math.multiply(dVec, rub.vec)
vecs.push([tag, dot, rpPos, rubPos, dVec])
})
above = vecs.filter(d => d[1] > 0)
above.sort((a, b) => a[1] - b[1])
if (above.length > 0 ) {
distAbove = above[0][1]
const rubAbove = allDataWithVectors.find(d => d.tag === above[0][0])
twists[0] = calcTwist(rub, rubAbove, leadChain)
bends[0] = calcBends(rub, rubAbove)
}
below = vecs.filter(d => d[1] < 0)
below.sort((a, b) => math.abs(a[1]) - math.abs(b[1]))
if (below.length > 0 ) {
distBelow = below[0][1]
const rubBelow = allDataWithVectors.find(d => d.tag === below[0][0])
twists[1] = calcTwist(rub, rubBelow, leadChain)
bends[1] = calcBends(rub, rubBelow)
}
const neighborChains = angles
.results
.filter(d => d.chainId1 === leadChain.chainId || d.chainId2 === leadChain.chainId)
.sort((a, b) => b.dist - a.dist)
if (neighborChains.length > 0) {
nc = neighborChains[0].dist
}
}
results.data.push([
rub.tag,
carbChain.carb.carbIndex,
carbChain.carb.volume,
carbChain.carb.concentration,
carbChain.carb.innerConcentration,
!carbVol.tagsInside.includes(rub.tag) ? 1 : 0,
inChain,
innerChain,
...partners,
distAbove,
distBelow,
nc,
...twists,
...bends
])
}
return results
}