You are on page 1of 5

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";
}
}

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;
}

private Product getProductFromStock(int cas){


for(Product p:stock){
if(p.getCasNumber()==cas){
return p;
}
}return null;
}

public void howManyProductsInStock (){


System.out.println("We have "+stock.length+" Products in stock");
}
}

public class Main {


public static void main(String[] args){
Product heroine = new Product("Heroine", 111235, 100, true, 5, 150);
Product ketamine = new Product("ketamine", 111236, 50, true, 3, 80);
Product lsd = new Product("LSD", 111237, 60, true, 1, 90);
Product[] stock = {heroine, ketamine, lsd};
ChemistryShop chemistryShop = new ChemistryShop(stock);
chemistryShop.isAvailableInStock(111237);
chemistryShop.sell(lsd);
chemistryShop.isAvailableInStock(111237);
}
}
public class Product {
private String name;
private int casNumber;
private int cost;
private boolean available;
private double quantity;
private double prize;

public Product(String name, int casNumber, int cost, boolean available,


double quantity,double prize) {
this.name = name;
this.casNumber = casNumber;
this.cost = cost;
this.available = available;
this.quantity = quantity;
this.prize = prize;
}

public String getName() {


return name;
}
public void setName(String name) {
this.name = name;
}
public int getCasNumber() {
return casNumber;
}
public void setCasNumber(int casNumber) {
this.casNumber = casNumber;
}
public int getCost() {
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public double getQuantity() {
return quantity;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
public double getPrize() {
return prize;
}
public void setPrize(double prize) {
this.prize = prize;
}
}

You might also like