#!/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.

# @ <SNIPPET>
from openeye import oechem
import sys

ifs = oechem.oemolistream(sys.argv[1])
ctr = oechem.OEFloatArray(3)
ext = oechem.OEFloatArray(3)
for mol in ifs.GetOEMols():
    box = [float("inf")] * 3 + [float("-inf")] * 3
    for conf in mol.GetConfs():
        oechem.OEGetCenterAndExtents(conf, ctr, ext)
        box[0] = min(box[0], ctr[0] - ext[0])
        box[1] = min(box[1], ctr[1] - ext[1])
        box[2] = min(box[2], ctr[2] - ext[2])
        box[3] = max(box[3], ctr[0] + ext[0])
        box[4] = max(box[4], ctr[1] + ext[1])
        box[5] = max(box[5], ctr[2] + ext[2])

    print("Bounding box for the conformers of " + mol.GetTitle())
    print("Lower Extent: %.3f %.3f %.3f" % (box[0], box[1], box[2]), end=" ")
    print("Upper Extent: %.3f %.3f %.3f" % (box[3], box[4], box[5]))
# @ </SNIPPET>
