Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(a.__class__, a.charge) for a in mol0.atoms
)
expected_bonds = {
frozenset({stk.N, stk.C}): 2,
frozenset({stk.C}): 2,
frozenset({stk.H, stk.N}): 4,
frozenset({stk.H, stk.C}): 6
}
assert expected_bonds == Counter(
frozenset({b.atom1.__class__, b.atom2.__class__})
for b in mol0.bonds
)
# Test that caching is working properly.
mol1 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine']
)
assert mol0 is not mol1
mol2 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine'],
use_cache=True
)
mol3 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine'],
use_cache=True
)
assert mol0 is not mol2 and mol1 is not mol2
for b in mol0.bonds
)
# Test that caching is working properly.
mol1 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['amine']
)
assert mol0 is not mol1
mol2 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['amine'],
use_cache=True
)
mol3 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['amine'],
use_cache=True
)
assert mol0 is not mol2 and mol1 is not mol2
assert mol2 is mol3
mol4 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['aldehyde'],
use_cache=True
)
assert mol3 is not mol4
# Make sure that charged molecules are handled correctly.
mol5 = stk.BuildingBlock.init_from_file(
def test_init_pdb(bb_dir):
mol0 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['amine']
)
# Test that all values are initialized correctly.
assert len(mol0.func_groups) == 2
fg_types = stk.dedupe(fg.fg_type.name for fg in mol0.func_groups)
assert sum(1 for _ in fg_types) == 1
assert len(mol0.atoms) == 15
assert len(mol0.bonds) == 14
atom_count = {
(stk.H, 0): 10,
(stk.N, 0): 2,
(stk.C, 0): 3
}
assert atom_count == Counter(
assert atom_count == Counter(
(a.__class__, a.charge) for a in mol5.atoms
)
expected_bonds = {
frozenset({stk.N, stk.C}): 2,
frozenset({stk.C}): 2,
frozenset({stk.H, stk.N}): 4,
frozenset({stk.H, stk.C}): 4
}
assert expected_bonds == Counter(
frozenset({b.atom1.__class__, b.atom2.__class__})
for b in mol5.bonds
)
mol6 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'negative_nitrogen.pdb'),
functional_groups=['amine'],
use_cache=True
)
assert mol6 is not mol5 and mol6 is not mol0
# Test that all values are initialized correctly.
assert len(mol6.func_groups) == 1
fg_types = stk.dedupe(fg.fg_type.name for fg in mol6.func_groups)
assert sum(1 for _ in fg_types) == 1
assert len(mol6.atoms) == 13
assert len(mol6.bonds) == 12
atom_count = {
(stk.C, 0): 3,
(stk.N, 0): 1,
(stk.N, -1): 1,
def test_init_mol(bb_dir):
mol0 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine']
)
# Test that all values are initialized correctly.
assert len(mol0.func_groups) == 2
fg_types = stk.dedupe(fg.fg_type.name for fg in mol0.func_groups)
assert sum(1 for _ in fg_types) == 1
assert len(mol0.atoms) == 15
assert len(mol0.bonds) == 14
atom_count = {
(stk.H, 0): 10,
(stk.N, 0): 2,
(stk.C, 0): 3
}
assert atom_count == Counter(
def test_write_pdb(amine2):
path = join(test_dir, 'test_write.pdb')
amine2.write(path=path)
bb = stk.BuildingBlock.init_from_file(path)
assert np.allclose(
a=amine2.get_position_matrix(),
b=bb.get_position_matrix(),
atol=1e-4
)
def c60():
return stk.BuildingBlock.init_from_file(
path=join('..', 'data', 'c60.pdb')
)
for b in mol0.bonds
)
# Test that caching is working properly.
mol1 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine']
)
assert mol0 is not mol1
mol2 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine'],
use_cache=True
)
mol3 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine'],
use_cache=True
)
assert mol0 is not mol2 and mol1 is not mol2
assert mol2 is mol3
mol4 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['aldehyde'],
use_cache=True
)
assert mol3 is not mol4
# Make sure that charged molecules are handled correctly.
mol5 = stk.BuildingBlock.init_from_file(
frozenset({stk.H, stk.N}): 4,
frozenset({stk.H, stk.C}): 6
}
assert expected_bonds == Counter(
frozenset({b.atom1.__class__, b.atom2.__class__})
for b in mol0.bonds
)
# Test that caching is working properly.
mol1 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine']
)
assert mol0 is not mol1
mol2 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine'],
use_cache=True
)
mol3 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['amine'],
use_cache=True
)
assert mol0 is not mol2 and mol1 is not mol2
assert mol2 is mol3
mol4 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.mol'),
functional_groups=['aldehyde'],
use_cache=True
assert mol0 is not mol1
mol2 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['amine'],
use_cache=True
)
mol3 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['amine'],
use_cache=True
)
assert mol0 is not mol2 and mol1 is not mol2
assert mol2 is mol3
mol4 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'neutral.pdb'),
functional_groups=['aldehyde'],
use_cache=True
)
assert mol3 is not mol4
# Make sure that charged molecules are handled correctly.
mol5 = stk.BuildingBlock.init_from_file(
path=join(bb_dir, 'negative_carbon.pdb'),
functional_groups=['amine'],
use_cache=True
)
assert mol5 is not mol0
# Test that all values are initialized correctly.
assert len(mol5.func_groups) == 2
fg_types = stk.dedupe(fg.fg_type.name for fg in mol5.func_groups)