-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
import sys | ||
import os | ||
import inspect | ||
import numpy as np | ||
import random | ||
current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) | ||
path_end_index=current_dir.find("dendrimer_dna") | ||
|
||
code_path=current_dir[0:path_end_index]+"dendrimer_dna" | ||
pyMBE_path = code_path + '/pyMBE' | ||
sys.path.insert(0, pyMBE_path) | ||
import pyMBE | ||
pmb = pyMBE.pymbe_library() | ||
|
||
|
||
#Defining variables for test | ||
center = [0, 0, 0] | ||
radius = 1 | ||
origin = [1, 2, 3] | ||
magnitude = 1 | ||
n = 10 | ||
tolerance = 1e-3 | ||
original_vector = pmb.generate_trialvectors(center=center,radius=radius, n_samples=1, seed=None, on_surface=True)[0] | ||
original_vector = pmb.generate_trialvectors(center=origin, | ||
radius=magnitude, | ||
n_samples=1, | ||
seed=None, | ||
on_surface=True)[0] | ||
perpendicular_vectors = [] | ||
for _ in range(n): | ||
perpendicular_vector = pmb.generate_trial_perpendicular_vector(original_vector, center, radius) | ||
perpendicular_vector = pmb.generate_trial_perpendicular_vector(vector=original_vector, | ||
origin=origin, | ||
magnitude=magnitude) | ||
perpendicular_vectors.append(perpendicular_vector) | ||
|
||
print(f"***Perpendicular vector unit test***") | ||
print(f"***Unit test: Checks that the generated vector is perpendicular to the original vector {n} times.***") | ||
print(f"*** generate_trial_perpendicular_vector unit tests ***") | ||
print(f"*** Unit test: Check that the function creates {n} perpendicular vectors to an input vector. ***") | ||
for vector in perpendicular_vectors: | ||
np.testing.assert_almost_equal(actual = np.dot(original_vector, vector), | ||
desired = 0, | ||
decimal = 5, | ||
verbose = True) | ||
print(f"***Unit test passed***") | ||
|
||
print(f"***Unit test: Checks that {n} generated perpendicular vectors are unique.***") | ||
print(f"***Unit test passed***") | ||
print(f"***Unit test: Check that the {n} perpendicular vectors are different.***") | ||
unique_set = set() | ||
for vector in perpendicular_vectors: | ||
vector_tuple = tuple(round(coord, 2) for coord in vector) | ||
unique_set.add(vector_tuple) | ||
np.testing.assert_equal(actual = len(unique_set), desired = n, verbose = True) | ||
np.testing.assert_equal(actual = len(unique_set), | ||
desired = n, | ||
verbose = True) | ||
print(f"***Unit test passed***") | ||
|
||
|
||
|
||
print(f"***Unit test: Checks that {n} generated perpendicular vectors have the same magnitude as the input vector {original_vector} generated by pyMBE function.***") | ||
print(f"***Unit test: Check that the perpendicular vectors have the same magnitude as the input magnitude.***") | ||
for vector in perpendicular_vectors: | ||
np.testing.assert_almost_equal(actual = np.linalg.norm(vector), desired = np.linalg.norm(original_vector), decimal = 5, verbose = True) | ||
np.testing.assert_almost_equal(actual = np.linalg.norm(vector), | ||
desired = magnitude, | ||
decimal = 5, | ||
verbose = True) | ||
print(f"***Unit test passed") | ||
print(f"*** All unit tests passed ***") |