Return a molecule object of the optimal geometry
343139
def get_optimized_molecule(self):
        """"""
        opt_coor = self.get_optimization_coordinates()
        if len(opt_coor) == 0:
            return None
        else:
            return Molecule(
                self.molecule.numbers,
                opt_coor[-1],
            )
317633
def assign_descriptors(mol):
    
    topology.recognize(mol)
    descriptor.assign_valence(mol)
    descriptor.assign_rotatable(mol)
    topology.minify_ring(mol)
    descriptor.assign_aromatic(mol)
555805
def from_rdmol(rdmol, assign_descriptor=True):
    """"""
    mol = Compound()
    conf = rdmol.GetConformer()
    Chem.Kekulize(rdmol)
    for atom in rdmol.GetAtoms():
        key = atom.GetIdx()
        a = Atom(atom.GetSymbol())
        a.coords = conf.GetAtomPosition(key)
        mol.add_atom(key, a)
    for bond in rdmol.GetBonds():
        u = bond.GetBeginAtomIdx()
        v = bond.GetEndAtomIdx()
        b = Bond()
        b.order = int(bond.GetBondTypeAsDouble())
        mol.add_bond(u, v, b)
    if assign_descriptor:
        molutil.assign_descriptors(mol)
    return mol
705537
def _parse_geometry(self, geom):
        
        atoms = []
        for i, line in enumerate(geom.splitlines()):
           sym, atno, x, y, z = line.split()
           atoms.append(Atom(sym, [float(x), float(y), float(z)], id=i))
        
        return Molecule(atoms)
1344356
def _get_nsymop(self):
        """"""
        if self.centrosymmetric:
            return 2 * len(self._rotations) * len(self._subtrans)
        else:
            return len(self._rotations) * len(self._subtrans)
1149754
public IAtom getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(IAtomContainer molecule) {
        Iterator<IBond> bonds = molecule.bonds().iterator();
        while (bonds.hasNext()) {
            IBond bond = bonds.next();
            if (bond.getBegin().getFlag(CDKConstants.ISPLACED) && !(bond.getEnd().getFlag(CDKConstants.ISPLACED))) {
                if (isAliphaticHeavyAtom(bond.getEnd())) {
                    return bond.getEnd();
                }
            }
            if (bond.getEnd().getFlag(CDKConstants.ISPLACED) && !(bond.getBegin().getFlag(CDKConstants.ISPLACED))) {
                if (isAliphaticHeavyAtom(bond.getBegin())) {
                    return bond.getBegin();
                }
            }
        }
        return null;
    }
985556
static public SimpleGraph getMoleculeGraph(IAtomContainer molecule) {
        SimpleGraph graph = new SimpleGraph();
        for (int i = 0; i < molecule.getAtomCount(); i++) {
            IAtom atom = molecule.getAtom(i);
            graph.addVertex(atom);
        }

        for (int i = 0; i < molecule.getBondCount(); i++) {
            IBond bond = molecule.getBond(i);

            /*
             * int order = (int) bond.getOrder(); for (int j=0; j<order; j++) {
             * graph.addEdge(bond.getAtoms()[0], bond.getAtoms()[1]); }
             */
            graph.addEdge(bond.getBegin(), bond.getEnd());
        }
        return graph;
    }
13963
def is_within(self, cutoff_dist, point, ligands=True):
        """"""
        return find_atoms_within_distance(self.get_atoms(ligands=ligands), cutoff_dist, point)
401934
def format_ring_double_bond(mol):
    
    mol.require("Topology")
    mol.require("ScaleAndCenter")
    for r in sorted(mol.rings, key=len, reverse=True):
        vertices = [mol.atom(n).coords for n in r]
        try:
            if geometry.is_clockwise(vertices):
                cpath = iterator.consecutive(itertools.cycle(r), 2)
            else:
                cpath = iterator.consecutive(itertools.cycle(reversed(r)), 2)
        except ValueError:
            continue
        for _ in r:
            u, v = next(cpath)
            b = mol.bond(u, v)
            if b.order == 2:
                b.type = int((u > v) == b.is_lower_first)
500277
private int getNearestBondtoAGivenAtom(IAtomContainer mol, IAtom atom, IBond bond) {
        int nearestBond = 0;
        double[] values;
        double distance = 0;
        IAtom atom0 = bond.getBegin();
        List<IBond> bondsAtLeft = mol.getConnectedBondsList(atom0);
        int partial;
        for (int i = 0; i < bondsAtLeft.size(); i++) {
            IBond curBond = bondsAtLeft.get(i);
            values = calculateDistanceBetweenAtomAndBond(atom, curBond);
            partial = mol.indexOf(curBond);
            if (i == 0) {
                nearestBond = mol.indexOf(curBond);
                distance = values[0];
            } else {
                if (values[0] < distance) {
                    nearestBond = partial;
                }
            }
        }
        return nearestBond;

    }
930413
def display_molecule(mol, style='ball-and-stick'):
    '''

    '''
    v = QtViewer()

    
    if style == 'ball-and-stick':
        bs = v.add_renderer(BallAndStickRenderer,
                            mol.r_array,
                            mol.type_array,
                            mol.bonds)
    elif style == 'vdw':
        sr = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array,
                            backend='impostors')
    else:
        raise Exception("Rendering style unknown")
    
    v.widget.camera.autozoom(mol.r_array)
    v.run()
599392
def _read_species_and_inital_geometry(self):
        
        header_pattern = r"Standard Nuclear Orientation \(Angstroms\)\s+I\s+Atom\s+X\s+Y\s+Z\s+-+"
        table_pattern = r"\s*\d+\s+([a-zA-Z]+)\s*([\d\-\.]+)\s*([\d\-\.]+)\s*([\d\-\.]+)\s*"
        footer_pattern = r"\s*-+"
        temp_geom = read_table_pattern(self.text, header_pattern,
                                       table_pattern, footer_pattern)
        if temp_geom == None or len(temp_geom) == 0:
            self.data["species"] = None
            self.data["initial_geometry"] = None
            self.data["initial_molecule"] = None
            self.data["point_group"] = None
        else:
            temp_point_group = read_pattern(
            self.text, {
                "key":
                r"Molecular Point Group\s+([A-Za-z\d\*]+)"
            },
            terminate_on_match=True).get('key')
            if temp_point_group != None:
                self.data["point_group"] = temp_point_group[0][0]
            else:
                self.data["point_group"] = None
            temp_geom = temp_geom[0]
            species = []
            geometry = np.zeros(shape=(len(temp_geom), 3), dtype=float)
            for ii, entry in enumerate(temp_geom):
                species += [entry[0]]
                for jj in range(3):
                    geometry[ii, jj] = float(entry[jj + 1])
            self.data["species"] = species
            self.data["initial_geometry"] = geometry
            self.data["initial_molecule"] = Molecule(
                species=species,
                coords=geometry,
                charge=self.data.get('charge'),
                spin_multiplicity=self.data.get('multiplicity'))
518343
def display_molecule(mol, autozoom=True):
    '''

    '''
    s = System([mol])
    display_system(s, autozoom=True)
539417
def get_first_molecule(self):
        
        title, coordinates = self._first
        molecule = Molecule(self.numbers, coordinates, title, symbols=self.symbols)
        return molecule
420449
private static GeometryEncoder encoder(ITetrahedralChirality tc, Map<IAtom, Integer> atomToIndex) {

        IAtom[] ligands = tc.getLigands();

        int centre = atomToIndex.get(tc.getChiralAtom());
        int[] indices = new int[4];

        int offset = -1;

        for (int i = 0; i < ligands.length; i++) {
            indices[i] = atomToIndex.get(ligands[i]);
            if (indices[i] == centre) offset = i;
        }

        // convert clockwise/anticlockwise to -1/+1
        int parity = tc.getStereo() == CLOCKWISE ? -1 : 1;

        // now if any atom is the centre (indicating an implicit
        // hydrogen) we need to adjust the indicies and the parity
        if (offset >= 0) {

            // remove the 'implicit' central from the first 3 vertices
            for (int i = offset; i < indices.length - 1; i++) {
                indices[i] = indices[i + 1];
            }

            // we now take how many vertices we moved which is
            // 3 (last index) minus the index where we started. if the
            // value is odd we invert the parity (odd number of
            // inversions)
            if (Integer.lowestOneBit(3 - offset) == 0x1) parity *= -1;

            // trim the array to size we don't include the last (implicit)
            // vertex when checking the invariants
            indices = Arrays.copyOf(indices, indices.length - 1);
        }

        return new GeometryEncoder(centre, new BasicPermutationParity(indices), GeometricParity.valueOf(parity));
    }
739914
def approximator(molecules, options, sort_order=None, frameworks=[], ensemble=[]):
    

    # set variables
    ensemble_size = options.ensemble_size

    if not sort_order:
        sort_order = classification.get_sort_order(molecules)

    # construct ensemble
    print("Performing calculations for ensemble size {s}".format(s=(len(ensemble) + 1)))
    ensemble = rank_queries(molecules, ensemble, sort_order, options)

    # write stats & ensemble
    output.write_ensemble(list(ensemble), options)

    if len(ensemble) == ensemble_size:
        return 1
    else:
        return approximator(molecules, options, sort_order, frameworks, ensemble)
1197803
private static GeometricParity geometric3D(int i, int[] adjacent, IAtomContainer container) {

        IAtom atom = container.getAtom(i);
        Point3d[] coordinates = new Point3d[4];

        // set the forth ligand to centre as default (overwritten if
        // we have 4 neighbors)
        if (atom.getPoint3d() != null)
            coordinates[3] = atom.getPoint3d();
        else
            return null;

        // for each neighboring atom check if we have 3D coordinates
        for (int j = 0; j < adjacent.length; j++) {
            IAtom neighbor = container.getAtom(adjacent[j]);

            if (neighbor.getPoint3d() != null)
                coordinates[j] = neighbor.getPoint3d();
            else
                return null; // skip to next atom
        }

        // add new 3D stereo encoder
        return new Tetrahedral3DParity(coordinates);

    }