⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atomtools.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            Point3d dPoint = ligandsWithCoords.getAtom(2).getPoint3d();            newPoints = new Point3d[1];            newPoints[0] = calculate3DCoordinates3(aPoint, bPoint, cPoint, dPoint, length);        }        return newPoints;    }            /**     * Calculates substituent points.     * Calculate substituent points for      * (0) zero ligands of aPoint. The resultant points are randomly oriented:     *    (i) 1 points  required; +x,0,0     *    (ii) 2 points: use +x,0,0 and -x,0,0     *    (iii) 3 points: equilateral triangle in xy plane     *    (iv) 4 points x,x,x, x,-x,-x, -x,x,-x, -x,-x,x where 3x**2 = bond length     *     * @param aPoint to which substituents are added     * @param nwanted number of points to calculate (1-4)     * @param length from aPoint     *     * @return Point3d[] nwanted points (or zero if failed)     */    public static Point3d[] calculate3DCoordinates0(Point3d aPoint, int nwanted, double length) {        Point3d points[] = new Point3d[0];        if (nwanted == 1) {            points = new Point3d[1];            points[0] = new Point3d(aPoint);            points[0].add(new Vector3d(length, 0.0, 0.0));        } else if (nwanted == 2) {            points[0] = new Point3d(aPoint);            points[0].add(new Vector3d(length, 0.0, 0.0));            points[1] = new Point3d(aPoint);            points[1].add(new Vector3d(-length, 0.0, 0.0));        } else if (nwanted == 3) {            points[0] = new Point3d(aPoint);            points[0].add(new Vector3d(length, 0.0, 0.0));            points[1] = new Point3d(aPoint);            points[1].add(new Vector3d(-length * 0.5, -length * 0.5 * Math.sqrt(3.0), 0.0f));            points[2] = new Point3d(aPoint);            points[2].add(new Vector3d(-length * 0.5, length * 0.5 * Math.sqrt(3.0), 0.0f));        } else if (nwanted == 4) {            double dx = length / Math.sqrt(3.0);            points[0] = new Point3d(aPoint);            points[0].add(new Vector3d(dx,  dx,  dx));            points[1] = new Point3d(aPoint);            points[1].add(new Vector3d(dx, -dx, -dx));            points[2] = new Point3d(aPoint);            points[2].add(new Vector3d(-dx, -dx,  dx));            points[3] = new Point3d(aPoint);            points[3].add(new Vector3d(-dx,  dx, -dx));        }        return points;    }        /**      * Calculate new point(s) X in a B-A system to form B-A-X.      * Use C as reference for * staggering about the B-A bond     *     * (1a) 1 ligand(B) of refAtom (A) which itself has a ligand (C)     *    (i) 1 points  required; vector along AB vector     *    (ii) 2 points: 2 vectors in ABC plane, staggered and eclipsed wrt C     *    (iii) 3 points: 1 staggered wrt C, the others +- gauche wrt C     * If C is null, a random non-colinear C is generated     *     * @param aPoint to which substituents are added     * @param nwanted number of points to calculate (1-3)     * @param length A-X length     * @param angle B-A-X angle     *     * @return Point3d[] nwanted points (or zero if failed)     */    public static Point3d[] calculate3DCoordinates1(        Point3d aPoint, Point3d bPoint, Point3d cPoint,         int nwanted,  double length, double angle) {        Point3d points[] = new Point3d[nwanted];// BA vector                Vector3d ba = new Vector3d(aPoint);        ba.sub(bPoint);        ba.normalize();// if no cPoint, generate a random reference        if (cPoint == null) {            Vector3d cVector = getNonColinearVector(ba);            cPoint = new Point3d(cVector);        }// CB vector        Vector3d cb = new Vector3d(bPoint);        cb.sub(cPoint);        cb.normalize();// if A, B, C colinear, replace C by random point                double cbdotba = cb.dot(ba);        if (cbdotba > 0.999999) {            Vector3d cVector = getNonColinearVector(ba);            cPoint = new Point3d(cVector);            cb = new Vector3d(bPoint);            cb.sub(cPoint);        }// cbxba = c x b                Vector3d cbxba = new Vector3d();        cbxba.cross(cb, ba);        cbxba.normalize();// create three perp axes ba, cbxba, and ax                Vector3d ax = new Vector3d();        ax.cross(cbxba, ba);        ax.normalize();        double drot = Math.PI * 2.0 / (double) nwanted;        for (int i = 0; i < nwanted; i++) {            double rot = (double) i * drot;            points[i] = new Point3d(aPoint);            Vector3d vx = new Vector3d(ba);            vx.scale(-Math.cos(angle) * length);            Vector3d vy = new Vector3d(ax);            vy.scale(Math.cos(rot) * length);            Vector3d vz = new Vector3d(cbxba);            vz.scale(Math.sin(rot) * length);            points[i].add(vx);            points[i].add(vy);            points[i].add(vz);        }        return points;    }        /**      * Calculate new point(s) X in a B-A-C system. It forms form a B-A(-C)-X system.     *     * (2) 2 ligands(B, C) of refAtom A     *    (i) 1 points  required; vector in ABC plane bisecting AB, AC. If ABC is     *        linear, no points     *    (ii) 2 points: 2 points X1, X2, X1-A-X2 = angle about 2i vector     *     * @param aPoint to which substituents are added     * @param bPoint first ligand of A     * @param cPoint second ligand of A     * @param nwanted number of points to calculate (1-2)     * @param length A-X length     * @param angle B-A-X angle     *     * @return Point3d[] nwanted points (or zero if failed)     */    public static Point3d[] calculate3DCoordinates2(      Point3d aPoint, Point3d bPoint, Point3d cPoint,        int nwanted, double length, double angle) {        Point3d newPoints[] = new Point3d[0];        double ang2 = angle / 2.0;                Vector3d ba = new Vector3d(aPoint);        ba.sub(bPoint);        Vector3d ca = new Vector3d(aPoint);        ca.sub(cPoint);        Vector3d baxca = new Vector3d();        baxca.cross(ba, ca);        if (baxca.length() < 0.00000001) {            ; // linear        } else if (nwanted == 1) {            newPoints = new Point3d[1];            Vector3d ax = new Vector3d(ba);            ax.add(ca);            ax.normalize();            ax.scale(length);            newPoints[0] = new Point3d(aPoint);            newPoints[0].add(ax);        } else if (nwanted == 2) {            newPoints = new Point3d[2];            Vector3d ax = new Vector3d(ba);             ax.add(ca);            ax.normalize();            baxca.normalize();            baxca.scale(Math.sin(ang2) * length);            ax.scale(Math.cos(ang2) * length);            newPoints[0] = new Point3d(aPoint);            newPoints[0].add(ax);            newPoints[0].add(baxca);            newPoints[1] = new Point3d(aPoint);            newPoints[1].add(ax);            newPoints[1].sub(baxca);        }        return newPoints;    }        /**      * Calculate new point X in a B-A(-D)-C system. It forms a B-A(-D)(-C)-X system.     *     * (3) 3 ligands(B, C, D) of refAtom A     *    (i) 1 points  required; if A, B, C, D coplanar, no points.      *       else vector is resultant of BA, CA, DA     *     * @param aPoint to which substituents are added     * @param bPoint first ligand of A     * @param cPoint second ligand of A     * @param dPoint third ligand of A     * @param length A-X length     *     * @return Point3d nwanted points (or null if failed (coplanar))     */    public static Point3d calculate3DCoordinates3(        Point3d aPoint, Point3d bPoint, Point3d cPoint, Point3d dPoint,          double length) {        Vector3d v1 = new Vector3d(aPoint);        v1.sub(bPoint);        Vector3d v2 = new Vector3d(aPoint);        v2.sub(cPoint);        Vector3d v3 = new Vector3d(aPoint);        v3.sub(dPoint);        Vector3d v = new Vector3d(bPoint);        v.add(cPoint);        v.add(dPoint);        if (v.length() < 0.00001) {            return null;        }        v.normalize();        v.scale(length);        Point3d point = new Point3d(aPoint);        point.add(v);        return point;    }        final static Vector3d XV = new Vector3d(1.0, 0.0, 0.0);    final static Vector3d YV = new Vector3d(0.0, 1.0, 0.0);    // gets a point not on vector a...b; this can be used to define a plan or cross products    private static Vector3d getNonColinearVector(Vector3d ab) {        Vector3d cr = new Vector3d();        cr.cross(ab, XV);        if (cr.length() > 0.00001) {            return XV;        } else {            return YV;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -