<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jtex.geom;

import com.jtex.arrays.Array1D;
import com.jtex.qta.file.BrukerGpolLoader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Scanner;

/**
 *
 * @author hios
 */
public class Symmetry extends Quaternion {

    public static enum Alignment {

        X_a("X||a"),
        X_astar("X||a*"),
        X_b("X||b"),
        X_bstar("X||b*"),
        Y_a("Y||a"),
        Y_astar("Y||a*"),
        Y_b("Y||b"),
        Y_bstar("Y||b*"),
        Z_c("Z||c"),
        Z_cstar("Z||c*");

        String alignment;

        private Alignment(String s) {
            this.alignment = s;
        }

        @Override
        public String toString() {
            return this.alignment;
        }

        public boolean isX() {
            return alignment.startsWith("X");
        }

        public boolean isY() {
            return alignment.startsWith("Y");
        }

        public boolean isZ() {
            return alignment.startsWith("Z");
        }

        public boolean isa() {
            return alignment.endsWith("a");
        }

        public boolean isastar() {
            return alignment.endsWith("a*");
        }

        public boolean isb() {
            return alignment.endsWith("b");
        }

        public boolean isbstar() {
            return alignment.endsWith("b*");
        }

        public boolean isc() {
            return alignment.endsWith("c");
        }

        public boolean iscstar() {
            return alignment.endsWith("c*");
        }

        public boolean is(String align) {
            return alignment.equals(align);
        }

        public static Alignment get(String align) {
            EnumSet<Alignment> allOf = EnumSet.allOf(Alignment.class);
            Iterator<Alignment> it = allOf.iterator();
            while (it.hasNext()) {
                Alignment next = it.next();
                if (next.is(align)) {
                    return next;
                }
            }
            return null;
        }
    }

//    Alignment alignX, alignY, alignZ;
    private static String hms2point(String s) {

        s = s.replaceAll("[ABCFIPR]", "");
        s = s.replaceAll("[abcdn]", "m");
        for (int i = 0; i < s.length() - 1; i++) {
            char ch = s.charAt(i);
            if (Character.isDigit(ch) && Character.isDigit(s.charAt(i + 1))) {
                s = s.substring(0, i + 1).concat(s.substring(i + 2));
            }
        }
        if (s.matches("[m2-6]")) {
            s = s.replace("1", "");
        }
        s = s.toLowerCase();

        return s;
    }

    public static Symmetry loadSampleCIF() {
        InputStream in = BrukerGpolLoader.class.getResourceAsStream("/com/jtex/data/cif/Mg-Magnesium.cif");
        return loadCIF(in);
    }

    public static Symmetry loadCIF(File cif) throws IOException {
        InputStream in = new FileInputStream(cif);
        Symmetry cs = loadCIF(in);
        in.close();
        return cs;
    }

    private static double parseDouble(String in) {

        in = in.trim();
        int ndx = in.indexOf("(");
        if (ndx > 0) {
            in = in.substring(0, ndx);
        }
        return Double.parseDouble(in);
    }

    public static Symmetry loadCIF(InputStream in) {
        Scanner scanner = new Scanner(in);
        double a = 0, b = 0, c = 0, alpha = 0, beta = 0, gamma = 0;
        String group = null;
        String line = null;
        while (scanner.hasNext()) {
            line = scanner.nextLine();
            if (line.startsWith("_cell_angle_alpha")) {
                alpha = Math.toRadians(parseDouble(line.substring(17)));
            } else if (line.startsWith("_cell_angle_beta")) {
                beta = Math.toRadians(parseDouble(line.substring(16)));
            } else if (line.startsWith("_cell_angle_gamma")) {
                gamma = Math.toRadians(parseDouble(line.substring(18)));
            } else if (line.startsWith("_cell_length_a")) {
                a = parseDouble(line.substring(14));
            } else if (line.startsWith("_cell_length_b")) {
                b = parseDouble(line.substring(14));
            } else if (line.startsWith("_cell_length_c")) {
                c = parseDouble(line.substring(14));
            } else if (line.startsWith("_symmetry_space_group_name_Hall")) {
                group = line.substring(31).trim();
            } else if (line.startsWith("_symmetry_space_group_name_H-M")) {
                group = line.substring(30).trim();
            } else if (line.startsWith("_symmetry_point_group_name_H-M")) {
                group = line.substring(30).trim();
            }
        }

        group = group.replaceAll("[ '/]", "");
        return new Symmetry(group, a, b, c, alpha, beta, gamma);
    }

    public static Vec3 calcAxis(double a, double b, double c, double alpha, double beta, double gamma, Alignment[] align) {
        double ca = Math.cos(alpha), cb = Math.cos(beta), cg = Math.cos(gamma), sg = Math.sin(gamma);
        double ys = (ca - cb * cg) / sg;<commit_msg>Updated cif keyword for space group importing phase<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jtex.geom;

import com.jtex.arrays.Array1D;
import com.jtex.qta.file.BrukerGpolLoader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Scanner;

/**
 *
 * @author hios
 */
public class Symmetry extends Quaternion {

    public static enum Alignment {

        X_a("X||a"),
        X_astar("X||a*"),
        X_b("X||b"),
        X_bstar("X||b*"),
        Y_a("Y||a"),
        Y_astar("Y||a*"),
        Y_b("Y||b"),
        Y_bstar("Y||b*"),
        Z_c("Z||c"),
        Z_cstar("Z||c*");

        String alignment;

        private Alignment(String s) {
            this.alignment = s;
        }

        @Override
        public String toString() {
            return this.alignment;
        }

        public boolean isX() {
            return alignment.startsWith("X");
        }

        public boolean isY() {
            return alignment.startsWith("Y");
        }

        public boolean isZ() {
            return alignment.startsWith("Z");
        }

        public boolean isa() {
            return alignment.endsWith("a");
        }

        public boolean isastar() {
            return alignment.endsWith("a*");
        }

        public boolean isb() {
            return alignment.endsWith("b");
        }

        public boolean isbstar() {
            return alignment.endsWith("b*");
        }

        public boolean isc() {
            return alignment.endsWith("c");
        }

        public boolean iscstar() {
            return alignment.endsWith("c*");
        }

        public boolean is(String align) {
            return alignment.equals(align);
        }

        public static Alignment get(String align) {
            EnumSet<Alignment> allOf = EnumSet.allOf(Alignment.class);
            Iterator<Alignment> it = allOf.iterator();
            while (it.hasNext()) {
                Alignment next = it.next();
                if (next.is(align)) {
                    return next;
                }
            }
            return null;
        }
    }

//    Alignment alignX, alignY, alignZ;
    private static String hms2point(String s) {

        s = s.replaceAll("[ABCFIPR]", "");
        s = s.replaceAll("[abcdn]", "m");
        for (int i = 0; i < s.length() - 1; i++) {
            char ch = s.charAt(i);
            if (Character.isDigit(ch) && Character.isDigit(s.charAt(i + 1))) {
                s = s.substring(0, i + 1).concat(s.substring(i + 2));
            }
        }
        if (s.matches("[m2-6]")) {
            s = s.replace("1", "");
        }
        s = s.toLowerCase();

        return s;
    }

    public static Symmetry loadSampleCIF() {
        InputStream in = BrukerGpolLoader.class.getResourceAsStream("/com/jtex/data/cif/Mg-Magnesium.cif");
        return loadCIF(in);
    }

    public static Symmetry loadCIF(File cif) throws IOException {
        InputStream in = new FileInputStream(cif);
        Symmetry cs = loadCIF(in);
        in.close();
        return cs;
    }

    private static double parseDouble(String in) {

        in = in.trim();
        int ndx = in.indexOf("(");
        if (ndx > 0) {
            in = in.substring(0, ndx);
        }
        return Double.parseDouble(in);
    }

    public static Symmetry loadCIF(InputStream in) {
        Scanner scanner = new Scanner(in);
        double a = 0, b = 0, c = 0, alpha = 0, beta = 0, gamma = 0;
        String group = null;
        String line = null;
        while (scanner.hasNext()) {
            line = scanner.nextLine();
            if (line.startsWith("_cell_angle_alpha")) {
                alpha = Math.toRadians(parseDouble(line.substring(17)));
            } else if (line.startsWith("_cell_angle_beta")) {
                beta = Math.toRadians(parseDouble(line.substring(16)));
            } else if (line.startsWith("_cell_angle_gamma")) {
                gamma = Math.toRadians(parseDouble(line.substring(18)));
            } else if (line.startsWith("_cell_length_a")) {
                a = parseDouble(line.substring(14));
            } else if (line.startsWith("_cell_length_b")) {
                b = parseDouble(line.substring(14));
            } else if (line.startsWith("_cell_length_c")) {
                c = parseDouble(line.substring(14));
            } else if (line.startsWith("_symmetry_space_group_name_Hall")) {
                group = line.substring(31).trim();
            } else if (line.startsWith("_symmetry_space_group_name_H-M")) {
                group = line.substring(30).trim();
            } else if (line.startsWith("_symmetry_point_group_name_H-M")) {
                group = line.substring(30).trim();
            } else if (line.startsWith("_space_group_name_H-M_alt")) {
	            group = line.substring(25).trim();
            } else if (line.startsWith("_space_group_name_Hall")) {
	            group = line.substring(22).trim();
            } else if (line.startsWith("_space_group_IT_number")) {
	            group = line.substring(22).trim();
            } else if (line.startsWith("_symmetry_Int_Tables_number")) {
	            group = line.substring(27).trim();
            }
        }

        group = group.replaceAll("[ '/]", "");
        return new Symmetry(group, a, b, c, alpha, beta, gamma);
    }

    public static Vec3 calcAxis(double a, double b, double c, double alpha, double beta, double gamma, Alignment[] align) {
        double ca = Math.cos(alpha), cb = Math.cos(beta), cg = Math.cos(gamma), sg = Math.sin(gamma);
        double ys = (ca - cb * cg) / sg;
{'fraction_non_alphanumeric': 0.13558566589409876, 'fraction_numerical': 0.0074879657692993404, 'mean_word_length': 1.8967208882003614, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3494709', 'n_tokens_mistral': 3458, 'n_tokens_neox': 3324, 'n_words': 744}