Skip to content

Instantly share code, notes, and snippets.

@andrewtarzia
Last active May 4, 2024 06:34
Show Gist options
  • Save andrewtarzia/23e7843365bad76277322e207d95e627 to your computer and use it in GitHub Desktop.
Save andrewtarzia/23e7843365bad76277322e207d95e627 to your computer and use it in GitHub Desktop.
bbprepared tutorial code
"""
MIT License
Copyright (c) 2023 Andrew Tarzia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import stk
import bbprep
import time
def distanced():
print("\ndoing distanced")
bb = stk.BuildingBlock(
smiles="C1=CC(=CN=C1)C2=NC=C(C=C2)C3=CC=NC=C3",
functional_groups=stk.SmartsFunctionalGroupFactory(
smarts="[#6]~[#7X2]~[#6]",
bonders=(1,),
deleters=(),
),
)
bb.write("distance_original.mol")
original_fgs = tuple(bb.get_functional_groups())
print(f"original: {original_fgs}")
modified = bbprep.ClosestFGs().modify(
building_block=bb,
desired_functional_groups=2,
)
modified_fgs = tuple(modified.get_functional_groups())
print(f"closest: {modified_fgs}")
modified = bbprep.FurthestFGs().modify(
building_block=bb,
desired_functional_groups=2,
)
modified_fgs = tuple(modified.get_functional_groups())
print(f"furthest: {modified_fgs}")
print("done\n")
def planarfy():
print("\ndoing planarfy")
bb = stk.BuildingBlock(
smiles=(
"C1=CC=C2C=C(C=CC2=C1)C3=CC(=CC=C3)C4=CC=CC5=CC=CC=C54"
),
)
bb.write("planar_original.mol")
selector = bbprep.selectors.AllSelector()
st = time.time()
generator = bbprep.generators.ETKDG(num_confs=10)
ensemble = generator.generate_conformers(bb)
print(ensemble)
process = bbprep.Planarfy(ensemble=ensemble, selector=selector)
min_molecule = process.get_minimum()
print("note that this gives a Conformer!")
min_molecule.molecule.write("planar_etkdg_final.mol")
min_score = process.calculate_score(
min_molecule, process.get_minimum_id()
)
print(
f"min score (etkdg): {min_score} ({round(time.time()-st, 2)}s)"
)
st = time.time()
generator = bbprep.generators.TorsionScanner(
target_torsions=bbprep.generators.TorsionRange(
smarts="[#6][#6]-!@[#6][#6]",
expected_num_atoms=4,
scanned_ids=(0, 1, 2, 3),
scanned_range=range(0, 362, 40),
),
)
ensemble = generator.generate_conformers(bb)
process = bbprep.Planarfy(ensemble=ensemble, selector=selector)
min_molecule = process.get_minimum()
min_molecule.molecule.write("planar_scan_final.mol")
min_score = process.calculate_score(
min_molecule, process.get_minimum_id()
)
print(
f"min score (scan): {min_score} ({round(time.time()-st, 2)}s)"
)
print("done\n")
def torsion():
print("\ndoing torsion")
bb = stk.BuildingBlock(smiles="C1=CC=NC(=C1)C2=CC=CC=N2")
bb.write("torsion_original.mol")
selector = bbprep.selectors.BySmartsSelector(
smarts="[#6][#7][#6][#6][#7][#6]",
selected_indices=(1, 2, 3, 4),
)
generator = bbprep.generators.TorsionScanner(
target_torsions=bbprep.generators.TorsionRange(
smarts="[#7][#6][#6][#7]",
expected_num_atoms=4,
scanned_ids=(0, 1, 2, 3),
scanned_range=range(0, 362, 20),
),
)
ensemble = generator.generate_conformers(bb)
target1 = 120
process = bbprep.TargetTorsion(
ensemble=ensemble,
selector=selector,
target_value=target1,
)
best_molecule = process.get_best()
best_molecule.molecule.write("torsion_target1.mol")
target2 = 60
process = bbprep.TargetTorsion(
ensemble=ensemble,
selector=selector,
target_value=target2,
)
best_molecule = process.get_best()
best_molecule.molecule.write("torsion_target2.mol")
print("done\n")
def ditopic():
print("\ndoing ditopic fitter")
bb = stk.BuildingBlock(
smiles="C1C=CN=CC=1C1=CC=C(C2C=NC=CC=2)C=C1",
functional_groups=stk.SmartsFunctionalGroupFactory(
smarts="[#6]~[#7X2]~[#6]",
bonders=(1,),
deleters=(),
),
)
bb.write("ditopic_original.mol")
generator = bbprep.generators.ETKDG(num_confs=30)
ensemble = generator.generate_conformers(bb)
process = bbprep.DitopicFitter(ensemble=ensemble)
min_molecule = process.get_minimum()
min_molecule.molecule.write("ditopic_final.mol")
print("done\n")
def main():
distanced()
planarfy()
torsion()
ditopic()
print("Thanks for watching!")
if __name__ == "__main__":
main()
@andrewtarzia
Copy link
Author

Updated on 04.05.24 to match new bbprep.generators.TorsionRange interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment