<commit_before>"""
cclib (http://cclib.sf.net) is (c) 2006, the cclib development team
and licensed under the LGPL (http://www.gnu.org/copyleft/lgpl.html).
"""

__revision__ = "$Revision$"

import pyopenbabel as pob
import openbabel as ob

def makeopenbabel(atomcoords, atomnos):
    """Create a list of pyopenbabel molecules.

    >>> import Numeric
    >>> atomnos = Numeric.array([1,8,1],"i")
    >>> a = Numeric.array([[-1,1,0],[0,0,0],[1,1,0]],"f")
    >>> pyOBmol = pyopenbabel(a,atomnos)
    >>> print pyOBmol.write("inchi").strip()
    InChI=1/H2O/h1H2
    """
# The only thing missing is charge, but this is also missing
# from cclib...things to do
    obmol = ob.OBMol()
    for coords, atomno in zip(atomcoords, atomnos):
        obatom = ob.OBAtom()
        obatom.SetAtomicNum(atomno)
        obatom.SetVector(*coords)
        obmol.AddAtom(obatom)
    obmol.ConnectTheDots()
    obmol.PerceiveBondOrders()
    return pob.Molecule(obmol)

if __name__ == "__main__":
    import doctest, cclib2openbabel
    doctest.testmod(cclib2openbabel)<commit_msg>Fixed open babel bridge: (1) No longer depends on pyopenbabel. (2) Weird Numeric effects caused SetVector to choke. Needed to convert the coords array to a list using .tolist() before SetVector would accept the parameters.<commit_after>"""
cclib (http://cclib.sf.net) is (c) 2006, the cclib development team
and licensed under the LGPL (http://www.gnu.org/copyleft/lgpl.html).
"""

__revision__ = "$Revision$"

import openbabel as ob

def makeopenbabel(atomcoords, atomnos):
    """Create an Open Babel molecule.

    >>> import Numeric, openbabel
    >>> atomnos = Numeric.array([1,8,1],"i")
    >>> coords = Numeric.array([[-1.,1.,0.],[0.,0.,0.],[1.,1.,0.]])
    >>> obmol = makeopenbabel(coords, atomnos)
    >>> obconversion = openbabel.OBConversion()
    >>> formatok = obconversion.SetOutFormat("inchi")
    >>> print obconversion.WriteString(obmol).strip()
    InChI=1/H2O/h1H2
    """
# The only thing missing is charge, but this is also missing
# from cclib...things to do
    obmol = ob.OBMol()
    for i in range(len(atomnos)):
        # Note that list(atomcoords[i]) is not equivalent!!!
        coords = atomcoords[i].tolist()
        atomno = atomnos[i]
        obatom = ob.OBAtom()
        obatom.SetAtomicNum(atomno)
        obatom.SetVector(*coords)
        obmol.AddAtom(obatom)
    obmol.ConnectTheDots()
    obmol.PerceiveBondOrders()
    return obmol

if __name__ == "__main__":
    import doctest
    doctest.testmod()
{'fraction_non_alphanumeric': 0.14422692768677586, 'fraction_numerical': 0.01757890531362365, 'mean_word_length': 3.511711711711712, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4874028', 'n_tokens_mistral': 935, 'n_tokens_neox': 881, 'n_words': 211}