Search in sources :

Example 1 with Molecule

use of uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Molecule 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)

Example 2 with Molecule

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

the class CreateData method logExampleCompounds.

private static void logExampleCompounds() {
    comment(TITLE + " example compounds");
    IJ.log("");
    comment("Compounds are described using parseable text.");
    comment("Missing fields are initialised to the default (0).");
    comment("Multiple compounds can be combined using fractional ratios.");
    comment("Coordinates are specified in nanometres.");
    comment("Coordinates describe the relative positions of atoms in the molecule;" + " the molecule will have a randomly assigned XYZ position for its centre-of-mass." + " Rotation will be about the centre-of-mass.");
    IJ.log("");
    final Molecule.Builder mb = Molecule.newBuilder();
    addAtom(mb, 10, 1, 1, 1);
    mb.setDiffusionRate(0.5);
    mb.setDiffusionType(DiffusionType.RANDOM_WALK.toString());
    final Molecule m1 = mb.build();
    mb.clear();
    addAtom(mb, 30, 0, 0, 0);
    addAtom(mb, 20, 1000, 0, 0);
    mb.setDiffusionRate(1);
    mb.setDiffusionType(DiffusionType.GRID_WALK.toString());
    final Molecule m2 = mb.build();
    // Create a hexamer big enough to see with the default pixel pitch
    mb.clear();
    addAtom(mb, 1, 0, 0, 0);
    addAtom(mb, 1, 1000, 0, 0);
    addAtom(mb, 1, 1500, 866, 0);
    addAtom(mb, 1, 1000, 1732, 0);
    addAtom(mb, 1, 0, 1732, 0);
    addAtom(mb, 1, -500, 866, 0);
    final Molecule m3 = mb.build();
    comment("Single molecules");
    IJ.log("");
    comment("Moving Monomer");
    demo(m1);
    comment("Moving Dimer");
    demo(m2);
    comment("Fixed Hexamer");
    demo(m3);
    comment("Mixtures of molecules");
    IJ.log("");
    comment("Two molecules with a ratio of 2:1");
    final Molecule m1a = m1.toBuilder().setFraction(2).build();
    final Molecule m2a = m2.toBuilder().setFraction(1).build();
    demo(m1a, m2a);
}
Also used : Molecule(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Molecule)

Example 3 with Molecule

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

the class CreateData method demo.

private static void demo(Molecule... molecules) {
    final Mixture.Builder builder = Mixture.newBuilder();
    for (final Molecule m : molecules) {
        builder.addMolecule(m);
    }
    // The toString() method is more verbose than JSON but easier to read
    IJ.log(builder.toString());
    IJ.log("");
}
Also used : Molecule(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Molecule) Mixture(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Mixture)

Aggregations

Molecule (uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Molecule)3 Mixture (uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.Mixture)2 IOException (java.io.IOException)1 AtomOrBuilder (uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.AtomOrBuilder)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