Appendix: Additional Examples in Python
Zap programming examples are dispersed among the descriptions of parts of the toolkits and in the overall chapter The Way of Zap. Full listings are provided here for examples that are presented as incomplete snippets in the Zap chapter.
Listing 1: OEBind.py full listing.
#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.
import sys
from openeye import oechem
from openeye import oezap
def ReadMolecule(filename):
mol = oechem.OEGraphMol()
ifs = oechem.oemolistream()
if not ifs.open(filename):
oechem.OEThrow.Fatal("Unable to open %s for reading", filename)
if not oechem.OEIs3DFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
if not oechem.OEReadMolecule(ifs, mol):
oechem.OEThrow.Fatal("Unable to read a molecule from %s", filename)
return mol
if len(sys.argv) != 3:
oechem.OEThrow.Usage("%s <protein> <ligand>" % sys.argv[0])
protein = ReadMolecule(sys.argv[1])
ligand = ReadMolecule(sys.argv[2])
bind = oezap.OEBind()
bind.SetProtein(protein)
results = oezap.OEBindResults()
bind.Bind(ligand, results)
results.Print(oechem.OEThrow)
bind = oezap.OEBind()
bind.GetZap().SetGridSpacing(0.6)
Listing 2: OEArea_GetArea.py full listing.
#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.
import sys
from openeye import oechem
from openeye import oezap
if len(sys.argv) != 2:
oechem.OEThrow.Usage("%s <molfile>" % sys.argv[0])
mol = oechem.OEGraphMol()
ifs = oechem.oemolistream()
if not ifs.open(sys.argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading", sys.argv[1])
if not oechem.OEIs3DFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
oechem.OEReadMolecule(ifs, mol)
oechem.OEAssignBondiVdWRadii(mol)
oechem.OEMMFFAtomTypes(mol)
oechem.OEMMFF94PartialCharges(mol)
area = oezap.OEArea()
a = area.GetArea(mol)
print("Molecule area =", a)
atomArea = oechem.OEFloatArray(mol.GetMaxAtomIdx())
area = oezap.OEArea()
area.GetArea(mol, atomArea)
for atom in mol.GetAtoms():
idx = atom.GetIdx()
print(idx, atomArea[idx])
area = oezap.OEArea()
for res in oechem.OEGetResidues(mol):
print (area.GetArea(mol, res))
atomArea = oechem.OEFloatArray(mol.GetMaxAtomIdx())
area = oezap.OEArea()
area.GetArea(mol, atomArea)
for res in oechem.OEGetResidues(mol):
print (area.GetArea(mol, atomArea, res))
Listing 3: DelPhiFlavor.py full listing.
#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.
from openeye import oechem
ifs = oechem.oemolistream()
ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default | oechem.OEIFlavor_PDB_DELPHI)