Skip to content

Assignment #2 #2

@JoaoRodrigues

Description

@JoaoRodrigues

Now that you have a working parser for PDB files, you can move to the next step of our project, which is to generate what's called a connectivity matrix between the atoms. This matrix has N rows and N columns, where N is the number of atoms you parsed. To build it, you iterate over each atom, and then again over all other atoms, and calculate the distance between each pair. The output is a matrix where you have 1 if the atoms are within a certain distance of each other, 0 otherwise.

The distance between two atoms, based on their 3D coordinates (x, y, z) is computed like this:

function euclideanDistance(x1, y1, z2, x2, y2, z2) {
    return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2))
}

You have to place it in a for-loop that looks more or less like this:

for (i=0; i < atoms.length; i++) {
    for (j=0; j < atoms.length; j++) {
        distance_ij = euclideanDistance(atoms[i][0], atoms[i][1], atoms[i][2], atoms[j][0], atoms[j][1], atoms[j][2])
    }
}

Bonus: Try to find a way to reduce the number of distances you need to make. Hint: the result of distance(i, j) is the same as distance(j, i).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions