-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type hinting and doc updating in tests #523
Closed
Closed
Conversation
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
Testing functions for this PR: def test1():
initial = stk.BuildingBlock(
smiles="C1=C(C(=C(C(=C1Br)Br)Br)Br)Br",
functional_groups=(stk.BromoFactory(),),
)
fgs = list(initial.get_functional_groups())
print(len(fgs))
rng = np.random.default_rng(seed=1000)
chosen_fgs = rng.choice(
fgs,
size=3,
replace=False,
)
print(len(chosen_fgs))
temp_molecule = initial.with_functional_groups(chosen_fgs)
# The fg_repr was not updating prior to this!
print(temp_molecule)
print(temp_molecule.get_num_functional_groups())
def get_disconnected_components(molecule):
# Produce a graph from the molecule that does not include edges
# where the bonds to be optimized are.
mol_graph = nx.Graph()
for atom in molecule.get_atoms():
mol_graph.add_node(atom.get_id())
# Add edges.
for bond in molecule.get_bonds():
pair_ids = (bond.get_atom1().get_id(), bond.get_atom2().get_id())
mol_graph.add_edge(*pair_ids)
# Get atom ids in disconnected subgraphs.
components = {}
for c in nx.connected_components(mol_graph):
c_ids = sorted(c)
molecule.write("temp_mol.mol", atom_ids=c_ids)
num_atoms = len(c_ids)
newbb = stk.BuildingBlock.init_from_file("temp_mol.mol")
os.system("rm temp_mol.mol")
components[num_atoms] = newbb
return components
def extract_host(molecule):
components = get_disconnected_components(molecule)
return components[max(components.keys())]
def extract_guest(molecule):
components = get_disconnected_components(molecule)
return components[min(components.keys())]
def test2():
host = stk.ConstructedMolecule(
topology_graph=stk.cage.FourPlusSix(
building_blocks=(
stk.BuildingBlock(
smiles="NC1CCCCC1N",
functional_groups=[
stk.PrimaryAminoFactory(),
],
),
stk.BuildingBlock(
smiles="O=Cc1cc(C=O)cc(C=O)c1",
functional_groups=[stk.AldehydeFactory()],
),
),
optimizer=stk.MCHammer(),
),
).with_centroid((0, 0, 0))
print("host:", host.get_centroid())
guest_bb = stk.BuildingBlock("C1=C(C(=C(C(=C1Br)Br)Br)Br)Br")
guest = stk.host_guest.Guest(
building_block=guest_bb,
start_vector=guest_bb.get_direction(),
end_vector=host.get_plane_normal(),
displacement=(0, 0, 0),
)
hgcomplex = stk.ConstructedMolecule(
topology_graph=stk.host_guest.Complex(
host=stk.BuildingBlock.init_from_molecule(host),
guests=guest,
),
)
hgcomplex.write("hg1.mol")
print("host 1", extract_host(hgcomplex).get_centroid())
extract_host(hgcomplex).write("eh_1.mol")
print("guest 1", extract_guest(hgcomplex).get_centroid())
extract_guest(hgcomplex).write("eg_1.mol")
print("----")
host = stk.ConstructedMolecule(
topology_graph=stk.cage.FourPlusSix(
building_blocks=(
stk.BuildingBlock(
smiles="NC1CCCCC1N",
functional_groups=[
stk.PrimaryAminoFactory(),
],
),
stk.BuildingBlock(
smiles="O=Cc1cc(C=O)cc(C=O)c1",
functional_groups=[stk.AldehydeFactory()],
),
),
optimizer=stk.MCHammer(),
),
).with_centroid((2, 3, 5))
print("host:", host.get_centroid())
guest = stk.host_guest.Guest(
building_block=guest_bb,
start_vector=guest_bb.get_direction(),
end_vector=host.get_plane_normal(),
displacement=host.get_centroid(),
)
hgcomplex = stk.ConstructedMolecule(
topology_graph=stk.host_guest.Complex(
host=stk.BuildingBlock.init_from_molecule(host),
guests=guest,
),
)
hgcomplex.write("hg2.mol")
print("host 2", extract_host(hgcomplex).get_centroid())
print("guest 2", extract_guest(hgcomplex).get_centroid())
extract_host(hgcomplex).write("eh_2.mol")
extract_guest(hgcomplex).write("eg_2.mol")
guest = stk.host_guest.Guest(
building_block=guest_bb,
start_vector=guest_bb.get_direction(),
end_vector=host.get_plane_normal(),
)
hgcomplex = stk.ConstructedMolecule(
topology_graph=stk.host_guest.Complex(
host=stk.BuildingBlock.init_from_molecule(host),
guests=guest,
),
)
hgcomplex.write("hg3.mol")
print("host 3", extract_host(hgcomplex).get_centroid())
print("guest 3", extract_guest(hgcomplex).get_centroid())
extract_host(hgcomplex).write("eh_3.mol")
extract_guest(hgcomplex).write("eg_3.mol")
raise SystemExit |
…cani#525) Some position matrices changed because I updated to the new numpy RNG instead of mixed old-numpy and `random.random` RNG in both packages.
Related Issues: lukasturcani#524 The existing implementation was overwriting the existing host vertex if the guest was the same building block as the vertex. Fix this by appending to the list of vertices that a given building block is attached to.
Some issue with rebasing! Tried again |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requested Reviewers: @lukasturcani
This PR will be slow going, but I will occasionally do folders in
tests
and update their doc strings to Google and add TypeHints.ruff
andmypy