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
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"; } }
public class Main {
public static void main (String[] args){ Atom hydrogen = new Atom(1,"H",1.007,120); Atom oxygen = new Atom(8,"O",15.999,60); Atom[]atoms = {hydrogen,oxygen,hydrogen}; InorganicMolecule water= new InorganicMolecule(atoms); double waterMass = water.calculateMolecularMass(); System.out.println("Your molecule have "+waterMass+" g/mol"); String structure = water.getStructure(); System.out.println("Your molecule structure is: "+structure);
Molecule m = new InorganicMolecule(atoms);
if (m instanceof OrganicMolecule){ ((InorganicMolecule) m).moleculeContains(); } } } public class ChemistryShop { private Product[] stock; private double income;
public ChemistryShop(Product[] stock) {
this.stock = stock; }
public boolean sell(Product product) {
if (isAvailableInStock(product.getCasNumber())) { income += product.getPrize();
for (Product p : stock) {
if (p.getCasNumber() == product.getCasNumber()) { p.setQuantity(p.getQuantity() - 1); } } System.out.println("the "+product.getName()+" was sold"); return true; } return false; }
public boolean isAvailableInStock(int cas){
Product p = getProductFromStock(cas); if(p!=null && p.getQuantity()!=0 ){ System.out.println("Yes we have "+ p.getName()+" on our stock"); return true; } System.out.println("Sorry ask another time"); return false; }