Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dir_vectors = tmp_amine4.get_bonder_direction_vectors()
for i, (id1, id2, v) in enumerate(dir_vectors):
# Calculate the expected direction vector based on ids.
d = stk.normalize_vector(np.array([id2]*3) - np.array([id1]*3))
assert np.allclose(d, stk.normalize_vector(v), atol=1e-8)
assert i == 5
# Test explicitly setting fg_ids.
dir_vectors = tmp_amine4.get_bonder_direction_vectors(
fg_ids=[0, 3]
)
for i, (id1, id2, v) in enumerate(dir_vectors):
# Calculate the expected direction vector based on ids.
d = stk.normalize_vector(np.array([id2]*3) - np.array([id1]*3))
assert np.allclose(d, stk.normalize_vector(v), atol=1e-8)
assert i == 0
tmp_amine2.set_position_matrix(coords)
assert np.allclose(
a=tmp_amine2.get_direction(),
b=[1, 0, 0],
atol=1e-8
)
coords[[1, 3]] = [[1, 1, 1], [3, 3, 3]]
tmp_amine2.set_position_matrix(coords)
all_atom_ids = ((1, 3), [1, 3], (i for i in [1, 3]))
for atom_ids in all_atom_ids:
assert np.allclose(
a=tmp_amine2.get_direction(atom_ids=atom_ids),
b=stk.normalize_vector([1, 1, 1]),
atol=1e-8
)
def _test_alignment(vertex, bb, target):
atom1, atom2 = bb.get_atom_coords([0, 1])
assert np.allclose(
a=stk.normalize_vector(atom1 - atom2),
b=target,
atol=1e-8
)
def _alignment(vertex, building_block):
fg_position = building_block.get_centroid(
atom_ids=building_block.func_groups[0].get_bonder_ids()
)
v1 = stk.normalize_vector(fg_position - vertex.get_position())
def inner(edge):
v2 = edge.get_position(vertex) - vertex.get_position()
return v1 @ stk.normalize_vector(v2)
return inner
def inner(edge):
edge_vector = edge.get_position() - vertex.get_position()
return fg_vector @ stk.normalize_vector(edge_vector)
def test_get_bonder_direction_vectors(tmp_amine4):
pos_mat = tmp_amine4.get_position_matrix()
# Set the coordinate of each bonder to the id of the fg.
for fg_id, fg in enumerate(tmp_amine4.func_groups):
for bonder in fg.get_bonder_ids():
pos_mat[bonder] = [fg_id, fg_id, fg_id]
tmp_amine4.set_position_matrix(pos_mat)
dir_vectors = tmp_amine4.get_bonder_direction_vectors()
for i, (id1, id2, v) in enumerate(dir_vectors):
# Calculate the expected direction vector based on ids.
d = stk.normalize_vector(np.array([id2]*3) - np.array([id1]*3))
assert np.allclose(d, stk.normalize_vector(v), atol=1e-8)
assert i == 5
# Test explicitly setting fg_ids.
dir_vectors = tmp_amine4.get_bonder_direction_vectors(
fg_ids=[0, 3]
)
for i, (id1, id2, v) in enumerate(dir_vectors):
# Calculate the expected direction vector based on ids.
d = stk.normalize_vector(np.array([id2]*3) - np.array([id1]*3))
assert np.allclose(d, stk.normalize_vector(v), atol=1e-8)
assert i == 0
def _alignment(vertex, building_block):
fg_position = building_block.get_centroid(
atom_ids=building_block.func_groups[0].get_bonder_ids()
)
fg_vector = stk.normalize_vector(
fg_position - vertex.get_position()
)
def inner(edge):
edge_vector = edge.get_position() - vertex.get_position()
return fg_vector @ stk.normalize_vector(edge_vector)
return inner
def test_apply_rotation_between_vectors(tmp_amine2):
assert not np.allclose(
a=next(tmp_amine2.get_bonder_direction_vectors())[-1],
b=[1, 0, 0],
atol=1e-8
)
tmp_amine2.apply_rotation_between_vectors(
start=next(tmp_amine2.get_bonder_direction_vectors())[-1],
target=[1, 0, 0],
origin=tmp_amine2.get_centroid()
)
assert np.allclose(
a=stk.normalize_vector(
next(tmp_amine2.get_bonder_direction_vectors())[-1]
),
b=[1, 0, 0],
atol=1e-8
)
def test_set_orientation2(tmp_amine2):
tmp_amine2.set_orientation2([1, 2, 3], 0)
vector = next(tmp_amine2.bonder_direction_vectors(0))[-1]
assert np.allclose(vector,
stk.normalize_vector([1, 2, 3]),
atol=1e-8)