Search in sources :

Example 1 with AtomOrBuilder

use of uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.AtomOrBuilder in project GDSC-SMLM by aherbert.

the class CreateData method createCompoundMolecules.

private List<CompoundMoleculeModel> createCompoundMolecules() {
    // Diffusion rate is um^2/sec. Convert to pixels per simulation frame.
    final double diffusionFactor = (1000000.0 / (settings.getPixelPitch() * settings.getPixelPitch())) / settings.getStepsPerSecond();
    List<CompoundMoleculeModel> compounds;
    if (settings.getCompoundMolecules()) {
        // Try and load the compounds from the text specification
        try {
            // Convert from the serialised objects to the compound model
            final String text = settings.getCompoundText();
            final Mixture.Builder builder = Mixture.newBuilder();
            TextFormat.merge(text, builder);
            compounds = new ArrayList<>(builder.getMoleculeCount());
            int id = 1;
            compoundNames = new ArrayList<>(builder.getMoleculeCount());
            for (final Molecule m : builder.getMoleculeList()) {
                final MoleculeModel[] molecules = new MoleculeModel[m.getAtomCount()];
                for (int i = 0; i < molecules.length; i++) {
                    final AtomOrBuilder a = m.getAtomOrBuilder(i);
                    molecules[i] = new MoleculeModel(a.getMass(), a.getX(), a.getY(), a.getZ());
                }
                final CompoundMoleculeModel cm = new CompoundMoleculeModel(id++, 0, 0, 0, Arrays.asList(molecules));
                cm.setFraction(m.getFraction());
                cm.setDiffusionRate(m.getDiffusionRate() * diffusionFactor);
                cm.setDiffusionType(DiffusionType.fromString(m.getDiffusionType()));
                compounds.add(cm);
                compoundNames.add(String.format("Fraction=%s, D=%s um^2/s", MathUtils.rounded(cm.getFraction()), MathUtils.rounded(m.getDiffusionRate())));
            }
            // Convert coordinates from nm to pixels
            final double scaleFactor = 1.0 / settings.getPixelPitch();
            for (final CompoundMoleculeModel c : compounds) {
                c.scale(scaleFactor);
            }
        } catch (final IOException ex) {
            IJ.error(TITLE, "Unable to create compound molecules");
            return null;
        }
    } else {
        // Create a simple compound with one molecule at the origin
        compounds = new ArrayList<>(1);
        final CompoundMoleculeModel m = new CompoundMoleculeModel(1, 0, 0, 0, Arrays.asList(new MoleculeModel(0, 0, 0, 0)));
        m.setDiffusionRate(settings.getDiffusionRate() * diffusionFactor);
        m.setDiffusionType(CreateDataSettingsHelper.getDiffusionType(settings.getDiffusionType()));
        compounds.add(m);
    }
    return compounds;
}
Also used : CompoundMoleculeModel(uk.ac.sussex.gdsc.smlm.model.CompoundMoleculeModel) IOException(java.io.IOException) Mixture(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Mixture) ReadHint(uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint) Molecule(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Molecule) MoleculeModel(uk.ac.sussex.gdsc.smlm.model.MoleculeModel) CompoundMoleculeModel(uk.ac.sussex.gdsc.smlm.model.CompoundMoleculeModel) AtomOrBuilder(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.AtomOrBuilder)

Aggregations

IOException (java.io.IOException)1 AtomOrBuilder (uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.AtomOrBuilder)1 Mixture (uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Mixture)1 Molecule (uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Molecule)1 CompoundMoleculeModel (uk.ac.sussex.gdsc.smlm.model.CompoundMoleculeModel)1 MoleculeModel (uk.ac.sussex.gdsc.smlm.model.MoleculeModel)1 ReadHint (uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint)1