<commit_before>package etomica.modules.colloid;

import etomica.api.IAtom;
import etomica.api.IBox;
import etomica.api.IMoleculeList;
import etomica.api.IRandom;
import etomica.api.ISpecies;
import etomica.api.IVector;
import etomica.api.IVectorMutable;
import etomica.atom.AtomArrayList;
import etomica.atom.AtomLeafAgentManager;
import etomica.config.Configuration;
import etomica.config.ConfigurationLattice;
import etomica.lattice.LatticeCubicFcc;
import etomica.space.ISpace;
import etomica.space.IVectorRandom;

public class ConfigurationColloid implements Configuration {

    public ConfigurationColloid(ISpace space, ISpecies species, ISpecies speciesColloid, IRandom random) {
        this.space = space;
        this.species = species;
        this.speciesColloid = speciesColloid;
        this.random = random;
    }
    
    public void setChainLength(int newChainLength) {
        chainLength = newChainLength;
    }
    
    public int getChainLength() {
        return chainLength;
    }
    
    public void setNGraft(int newNGraft) {
        if (newNGraft == nGraft) return;
        nGraft = newNGraft;
        graftVectors = new IVectorMutable[nGraft];
        for (int i=0; i<nGraft; i++) {
            graftVectors[i] = space.makeVector();
        }
        if (nGraft == 1) {
            graftVectors[0].setX(0,1);
        }
        else if (nGraft == 2) {
            graftVectors[0].setX(0,1);
            graftVectors[1].setX(0,-1);
        }
        else if (nGraft == 4) {
            double x = 1.0/Math.sqrt(3);
            graftVectors[0].E(new double[]{ x, x, x});
            graftVectors[1].E(new double[]{-x,-x, x});
            graftVectors[2].E(new double[]{-x, x,-x});
            graftVectors[3].E(new double[]{ x,-x,-x});
        }
        else if (nGraft == 6) {
            graftVectors[0].setX(0,1);
            graftVectors[1].setX(0,-1);
            graftVectors[2].setX(1,1);
            graftVectors[3].setX(1,-1);
            graftVectors[4].setX(2,1);
            graftVectors[5].setX(2,-1);
        }
        else if (nGraft == 8) {
            IVectorMutable v = space.makeVector();
            v.E(1);
            for (int i=0; i<8; i++) {
                graftVectors[i].E(1.0/Math.sqrt(3));
                graftVectors[i].TE(v);
                for (int j=2; j>-1; j--) {
                    if (v.getX(j) == 1) {
                        v.setX(j, -1);
                        break;
                    }
                    v.setX(j, 1);
                }
            }
        }
        else if (nGraft == 12) {
            double phi = (1+Math.sqrt(5))/2;
            double x1 = 1/Math.sqrt(phi*phi+1);
            double x2 = phi*x1;

            graftVectors[0].E(new double[]{  0, x1, x2});
            graftVectors[1].E(new double[]{  0, x1,-x2});
            graftVectors[2].E(new double[]{  0,-x1, x2});
            graftVectors[3].E(new double[]{  0,-x1,-x2});
            graftVectors[4].E(new double[]{ x1, x2,  0});
            graftVectors[5].E(new double[]{ x1,-x2,  0});
            graftVectors[6].E(new double[]{-x1, x2,  0});
            graftVectors[7].E(new double[]{-x1,-x2,  0});
            graftVectors[8].E(new double[]{ x2,  0, x1});
            graftVectors[9].E(new double[]{ x2,  0,-x1});
            graftVectors[10].E(new double[]{-x2,  0, x1});
            graftVectors[11].E(new double[]{-x2,  0,-x1});
        }
        else if (nGraft == 20) {
            double phi = (1+Math.sqrt(5))/2;
            double x1 = 1/Math.sqrt(3);
            double x2 = x1*phi;
            double x3 = x1/phi;
            graftVectors[0].E(new double[]{ x1, x1, x1});
            graftVectors[1].E(new double[]{ x1, x1,-x1});
            graftVectors[2].E(new double[]{ x1,-x1, x1});
            graftVectors[3].E(new double[]{ x1,-x1,-x1});
            graftVectors[4].E(new double[]{-x1, x1, x1});
            graftVectors[5].E(new double[]{-x1, x1,-x1});
            graftVectors[6].E(new double[]{-x1,-x1, x1});
            graftVectors[7].E(new double[]{-x1,-x1,-x1});
            graftVectors[8].E(new double[]{  0, x3, x2});
            graftVectors[9].E(new double[]{  0, x3,-x2});
            graftVectors[10].E(new double[]{  0,-x3, x2});
            graftVectors[11].E(new double[]{  0,-x3,-x2});
            graftVectors[12].E(new double[]{ x3, x2,  0});
            graftVectors[13].E(new double[]{ x3,-x2,  0});
            graftVectors[14].E(new double[]{-x3, x2,  0});
            graftVectors[15].E(new double[]{-x3,-x2,  0});
            graftVectors[16].E(new double[]{ x2,  0, x3});
            graftVectors[17].E(new double[]{ x2,  0,-x3});
            graftVectors[18].E(new double[]{-x2,  0, x3});
            graftVectors[19].E(new double[]{-x2,  0,-x3});
        }
        else {
            throw new RuntimeException("don't know how to do nGraft = "+nGraft);
        }
    }
    
    public int getNGraft() {
        return nGraft;
    }
    
    public void setSigmaColloid(double newSigmaColloid) {
        sigmaColloid = newSigmaColloid;
    }
    
    public void setSigmaMonomer(double newSigmaMonomer) {
        sigmaMonomer = newSigmaMonomer;
    }
    
    public double getSigmaColloid() {
        return sigmaColloid;
    }
    
    public double getSigmaMonomer() {
        return sigmaMonomer;
    }
    
    public void setMonomerMonomerBondManager(AtomLeafAgentManager newMonomerMonomerBondManager) {
        monomerMonomerBondManager = newMonomerMonomerBondManager;
    }
    
    public void setColloidMonomerBondManager(AtomLeafAgentManager newColloidMonomerBondManager) {
        colloidMonomerBondManager = newColloidMonomerBondManager;
    }
    
    public void initializeCoordinates(IBox box) {
        box.setNMolecules(species, 0);
        box.setNMolecules(species, nGraft*chainLength);
        if (chainLength*nGraft == 0) {
            return;
        }
        
        IMoleculeList monomerList = box.getMoleculeList(species);
        IMoleculeList colloidList = box.getMoleculeList(speciesColloid);
        IAtom previousAtom = null;
        int iMonomer = 0;
        IVectorMutable dr = space.makeVector();
        IVectorRandom temp = (IVectorRandom)space.makeVector();
        IVectorMutable lastPos = space.makeVector();

        box.setNMolecules(speciesColloid, 1);
        IAtom colloidAtom = colloidList.getMolecule(0).getChildList().getAtom(0);
        ((AtomArrayList)colloidMonomerBondManager.getAgent(colloidAtom)).clear();
        IVectorMutable colloidPos = colloidAtom.getPosition();
        colloidPos.E(0);
        for (int j=0; j<nGraft; j++) {
            lastPos.E(colloidPos);<commit_msg>ensure the colloid is inserted before bailling when there are no monomers<commit_after>package etomica.modules.colloid;

import etomica.api.IAtom;
import etomica.api.IBox;
import etomica.api.IMoleculeList;
import etomica.api.IRandom;
import etomica.api.ISpecies;
import etomica.api.IVector;
import etomica.api.IVectorMutable;
import etomica.atom.AtomArrayList;
import etomica.atom.AtomLeafAgentManager;
import etomica.config.Configuration;
import etomica.config.ConfigurationLattice;
import etomica.lattice.LatticeCubicFcc;
import etomica.space.ISpace;
import etomica.space.IVectorRandom;

public class ConfigurationColloid implements Configuration {

    public ConfigurationColloid(ISpace space, ISpecies species, ISpecies speciesColloid, IRandom random) {
        this.space = space;
        this.species = species;
        this.speciesColloid = speciesColloid;
        this.random = random;
    }
    
    public void setChainLength(int newChainLength) {
        chainLength = newChainLength;
    }
    
    public int getChainLength() {
        return chainLength;
    }
    
    public void setNGraft(int newNGraft) {
        if (newNGraft == nGraft) return;
        nGraft = newNGraft;
        graftVectors = new IVectorMutable[nGraft];
        for (int i=0; i<nGraft; i++) {
            graftVectors[i] = space.makeVector();
        }
        if (nGraft == 1) {
            graftVectors[0].setX(0,1);
        }
        else if (nGraft == 2) {
            graftVectors[0].setX(0,1);
            graftVectors[1].setX(0,-1);
        }
        else if (nGraft == 4) {
            double x = 1.0/Math.sqrt(3);
            graftVectors[0].E(new double[]{ x, x, x});
            graftVectors[1].E(new double[]{-x,-x, x});
            graftVectors[2].E(new double[]{-x, x,-x});
            graftVectors[3].E(new double[]{ x,-x,-x});
        }
        else if (nGraft == 6) {
            graftVectors[0].setX(0,1);
            graftVectors[1].setX(0,-1);
            graftVectors[2].setX(1,1);
            graftVectors[3].setX(1,-1);
            graftVectors[4].setX(2,1);
            graftVectors[5].setX(2,-1);
        }
        else if (nGraft == 8) {
            IVectorMutable v = space.makeVector();
            v.E(1);
            for (int i=0; i<8; i++) {
                graftVectors[i].E(1.0/Math.sqrt(3));
                graftVectors[i].TE(v);
                for (int j=2; j>-1; j--) {
                    if (v.getX(j) == 1) {
                        v.setX(j, -1);
                        break;
                    }
                    v.setX(j, 1);
                }
            }
        }
        else if (nGraft == 12) {
            double phi = (1+Math.sqrt(5))/2;
            double x1 = 1/Math.sqrt(phi*phi+1);
            double x2 = phi*x1;

            graftVectors[0].E(new double[]{  0, x1, x2});
            graftVectors[1].E(new double[]{  0, x1,-x2});
            graftVectors[2].E(new double[]{  0,-x1, x2});
            graftVectors[3].E(new double[]{  0,-x1,-x2});
            graftVectors[4].E(new double[]{ x1, x2,  0});
            graftVectors[5].E(new double[]{ x1,-x2,  0});
            graftVectors[6].E(new double[]{-x1, x2,  0});
            graftVectors[7].E(new double[]{-x1,-x2,  0});
            graftVectors[8].E(new double[]{ x2,  0, x1});
            graftVectors[9].E(new double[]{ x2,  0,-x1});
            graftVectors[10].E(new double[]{-x2,  0, x1});
            graftVectors[11].E(new double[]{-x2,  0,-x1});
        }
        else if (nGraft == 20) {
            double phi = (1+Math.sqrt(5))/2;
            double x1 = 1/Math.sqrt(3);
            double x2 = x1*phi;
            double x3 = x1/phi;
            graftVectors[0].E(new double[]{ x1, x1, x1});
            graftVectors[1].E(new double[]{ x1, x1,-x1});
            graftVectors[2].E(new double[]{ x1,-x1, x1});
            graftVectors[3].E(new double[]{ x1,-x1,-x1});
            graftVectors[4].E(new double[]{-x1, x1, x1});
            graftVectors[5].E(new double[]{-x1, x1,-x1});
            graftVectors[6].E(new double[]{-x1,-x1, x1});
            graftVectors[7].E(new double[]{-x1,-x1,-x1});
            graftVectors[8].E(new double[]{  0, x3, x2});
            graftVectors[9].E(new double[]{  0, x3,-x2});
            graftVectors[10].E(new double[]{  0,-x3, x2});
            graftVectors[11].E(new double[]{  0,-x3,-x2});
            graftVectors[12].E(new double[]{ x3, x2,  0});
            graftVectors[13].E(new double[]{ x3,-x2,  0});
            graftVectors[14].E(new double[]{-x3, x2,  0});
            graftVectors[15].E(new double[]{-x3,-x2,  0});
            graftVectors[16].E(new double[]{ x2,  0, x3});
            graftVectors[17].E(new double[]{ x2,  0,-x3});
            graftVectors[18].E(new double[]{-x2,  0, x3});
            graftVectors[19].E(new double[]{-x2,  0,-x3});
        }
        else {
            throw new RuntimeException("don't know how to do nGraft = "+nGraft);
        }
    }
    
    public int getNGraft() {
        return nGraft;
    }
    
    public void setSigmaColloid(double newSigmaColloid) {
        sigmaColloid = newSigmaColloid;
    }
    
    public void setSigmaMonomer(double newSigmaMonomer) {
        sigmaMonomer = newSigmaMonomer;
    }
    
    public double getSigmaColloid() {
        return sigmaColloid;
    }
    
    public double getSigmaMonomer() {
        return sigmaMonomer;
    }
    
    public void setMonomerMonomerBondManager(AtomLeafAgentManager newMonomerMonomerBondManager) {
        monomerMonomerBondManager = newMonomerMonomerBondManager;
    }
    
    public void setColloidMonomerBondManager(AtomLeafAgentManager newColloidMonomerBondManager) {
        colloidMonomerBondManager = newColloidMonomerBondManager;
    }
    
    public void initializeCoordinates(IBox box) {
        box.setNMolecules(species, 0);
        box.setNMolecules(species, nGraft*chainLength);
        box.setNMolecules(speciesColloid, 1);

        IMoleculeList colloidList = box.getMoleculeList(speciesColloid);
        IAtom colloidAtom = colloidList.getMolecule(0).getChildList().getAtom(0);
        ((AtomArrayList)colloidMonomerBondManager.getAgent(colloidAtom)).clear();
        IVectorMutable colloidPos = colloidAtom.getPosition();
        colloidPos.E(0);

        if (chainLength*nGraft == 0) {
            return;
        }
        
        IMoleculeList monomerList = box.getMoleculeList(species);
        IAtom previousAtom = null;
        int iMonomer = 0;
        IVectorMutable dr = space.makeVector();
        IVectorRandom temp = (IVectorRandom)space.makeVector();
        IVectorMutable lastPos = space.makeVector();

        for (int j=0; j<nGraft; j++) {
            lastPos.E(colloidPos);
{'fraction_non_alphanumeric': 0.1440347721822542, 'fraction_numerical': 0.03312350119904077, 'mean_word_length': 2.08056325023084, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3633077', 'n_tokens_mistral': 4943, 'n_tokens_neox': 4701, 'n_words': 816}