Códigos de Java
Manuel EscobarInforme19 de Octubre de 2018
2.022 Palabras (9 Páginas)170 Visitas
Página 1 de 9
public class ReactionTest { public static void main(String [] args) throws CDKException, IOException { //Crea una instancia sin crear nuevo elemento! IChemObjectBuilder iChemObjectBuilder = SilentChemObjectBuilder.getInstance(); //Convierte el texto a una molecula SmilesParser smilesParser = new SmilesParser(iChemObjectBuilder); //smilesParser crea la referencia;pareseSmiles es un método que devuelve IAtomContainer IAtomContainer ethanol = smilesParser.parseSmiles("CCO"); IAtomContainer aceticAcid = smilesParser.parseSmiles("CC=OO"); IAtomContainer bleach = smilesParser.parseSmiles("ClO");
Reaction reaction = new Reaction(); ethanol.setProperty(CDKConstants.TITLE,"Ethanol");//Crea un título a la imagen reaction.setProperty(CDKConstants.TITLE,"reaction1");//Crea tíyulo a la reacción reaction.addReactant(ethanol); reaction.addAgent(bleach); reaction.addProduct(aceticAcid);
DepictionGenerator depictionGenerator = new DepictionGenerator(); depictionGenerator = depictionGenerator.withFillToFit().withAtomColors() .withSize(500,500).withMolTitle().withRxnTitle(); //Usando ambos títulos //Al depict() se le asigna un elemento de IAtomContainer depictionGenerator.depict(reaction).writeTo("reaction.png"); depictionGenerator.depict(ethanol).writeTo("ethanol.png"); } } |
public class Test { public static void main(String [] args) throws CDKException, IOException { IAtom hydrogen = new Atom(Elements.HYDROGEN); IAtom hydrogen2 = new Atom("H"); IBond bond1 = new Bond(hydrogen,hydrogen2,IBond.Order.SINGLE); IAtomContainer molecularHydrogen = new AtomContainer(); molecularHydrogen.addAtom(hydrogen); molecularHydrogen.addAtom(hydrogen2); molecularHydrogen.addBond(bond1); for(IAtom atom:molecularHydrogen.atoms()){ System.out.println(atom.getSymbol()); } Ring cylohexane = new Ring(6,"CH"); Ring benzene = cylohexane; int i=2; for(IBond bond:benzene.bonds()){ bond.setIsAromatic(true); if(i%2==0){ bond.setOrder(IBond.Order.DOUBLE); } i++; } DepictionGenerator depictionGenerator = new DepictionGenerator(); depictionGenerator = depictionGenerator.withAtomColors().withFillToFit() .withSize(500,500); depictionGenerator.depict(benzene).writeTo("benzene.png"); //depict returns a class from the same hierarchy as the class depictionGenerator // depict generate the molecule you passed
String lsdSmile = "CCN(CC)C(=O)[C@H]1CN([C@@H]2Cc3c[nH]c4c3c(ccc4)C2=C1)C"; IChemObjectBuilder objectBuilder = SilentChemObjectBuilder.getInstance(); SmilesParser smilesParser = new SmilesParser(objectBuilder); smilesParser.parseSmiles(lsdSmile); IAtomContainer lsd = smilesParser.parseSmiles(lsdSmile); depictionGenerator.depict(lsd).writeTo("lsd.png"); //Parser takes a string and return another thing } } public class Atom { private int atomicNumber; private String symbol; private double weigth; private double radii;
public Atom(int atomicNumber, String symbol, double weigth, double radii) { this.atomicNumber = atomicNumber; this.symbol = symbol; this.weigth = weigth; this.radii = radii; } public int getAtomicNumber() { return atomicNumber; } public void setAtomicNumber(int atomicNumber) { this.atomicNumber = atomicNumber; } public String getSymbol() { return symbol; } public void setSymbol(String symbol) { this.symbol = symbol; } public double getWeigth() { return weigth; } public void setWeigth(double weigth) { this.weigth = weigth; } public double getRadii() { return radii; } public void setRadii(double radii) { this.radii = radii; } }
|
public class InorganicMolecule extends Molecule { private Atom[] atoms; public InorganicMolecule(Atom[] atoms){ super(atoms); this.atoms=atoms; }
public String moleculeContains(){ return " lack of C-H carbons"; } } |
public class OrganicMolecule extends Molecule{ private Atom[] atoms; public OrganicMolecule(){} public OrganicMolecule(Atom[] atoms) { super(atoms); this.atoms = atoms; } public String moleculeContains(){ return " contains C-H bonds"; } } |
public abstract class Molecule{ private Atom[]atoms; public Molecule(){} public Molecule(Atom[]atoms){ this.atoms=atoms; }
public String moleculeContains(){ return "Molecule"; }
public String getStructure(){ String s =""; for (Atom a: atoms){ s+=a.getSymbol()+"-"; } return s.substring(0,s.length()-1); }
private double sum=0; public double calculateMolecularMass(){ for(Atom a:atoms){ sum+= a.getWeigth(); } return sum; } } public class OrganicMolecule extends Molecule{ private Atom[] atoms; public OrganicMolecule(){} public OrganicMolecule(Atom[] atoms) { super(atoms); this.atoms = atoms; } public String moleculeContains(){ return " contains C-H bonds"; } } |
Disponible sólo en Clubensayos.com