1 CE 530 Molecular Simulation Lecture 4 Object-Oriented Programming and Etomica David A. Kofke Department of Chemical Engineering SUNY Buffalo

Slides:



Advertisements
Similar presentations
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Advertisements

The Web Warrior Guide to Web Design Technologies
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 CE 530 Molecular Simulation Lecture 2 David A. Kofke Department of Chemical Engineering SUNY Buffalo
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
All About Meters David A. Kofke Department of Chemical Engineering University at Buffalo, State University of New York.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
OOP Languages: Java vs C++
CE 400 Honors Seminar Molecular Simulation Prof. Kofke Department of Chemical Engineering University at Buffalo, State University of New York Class 1.
Introduction To System Analysis and design
Programming Languages and Paradigms Object-Oriented Programming.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
CS413: Java Programming language Applications Applets
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
©2007 · Georges Merx and Ronald J. NormanSlide 1 Chapter 3 The Structure and Syntax of Java.
Introduction to Object-oriented programming and software development Lecture 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Introduction to Programming Languages. Problem Solving in Programming.
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
CE 400 Honors Seminar Molecular Simulation Prof. Kofke Department of Chemical Engineering University at Buffalo, State University of New York Class 2.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
POS 406 Java Technology And Beginning Java Code
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
1 CE 530 Molecular Simulation Lecture 6 David A. Kofke Department of Chemical Engineering SUNY Buffalo
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
1 CE 530 Molecular Simulation Lecture 4 Object-Oriented Programming and Etomica David A. Kofke Department of Chemical Engineering SUNY Buffalo
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Creating a Java Application and Applet
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
All About Potentials and Iterators David A. Kofke Department of Chemical Engineering University at Buffalo, State University of New York.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Statistical Mechanics and Multi-Scale Simulation Methods ChBE
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Modern Programming Tools And Techniques-I
University of Central Florida COP 3330 Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Design Patterns A Case Study: Designing a Document Editor
Java Applets.
Object-Oriented Software Engineering
Introduction to Data Structure
Introducing Java.
Presentation transcript:

1 CE 530 Molecular Simulation Lecture 4 Object-Oriented Programming and Etomica David A. Kofke Department of Chemical Engineering SUNY Buffalo

2 Object-Oriented Programming  Programming accomplished through the actions and interactions of objects everything is an object  Forces abstract thinking about the structure and activities of a program  Promotes re-use of code and extension to new applications  Good design is difficult to develop requires thorough understanding of application conversely, its use facilitates a better understanding of application presents a good vehicle for teaching  It’s fun!

3 What is an Object?  A fancy variable stores data can perform operations using the data  Every object has a type, or “class” analogous to real, integer, etc. Fortran:real x, y, z Java:Atom a1, a2; you define types (classes) as needed to solve your problems public class Atom { double mass; Vector r, p; } types differ in the data they hold and the actions they can perform on it every object is an “instance of a class” a1 = new Atom();

4 Makeup of an Object  Fields (data) primitive types (integer, float, double, boolean, etc.) handles to other objects complex objects are composed from simpler objects (composition)  Methods (actions) “subroutines and functions” may take arguments and return values have complete access to all fields of object  A class has an interface what the object presents to enable its manipulation implementation (how it accomplishes its operations) can be hidden object is viewed in terms of its “actions” and not its “thoughts”  Inheritance can define subclasses which inherit features of parent class same interface, but different implementations subclasses can be used anywhere parent class is expected mechanism to change behavior of simulation

5 Detailed Look: Atom  Click here for the complete API specification Click here Atom coord Space parentGroup (via node) next (via seq) previous (via seq) ia Integrator allatomAgents[] any classes type AtomFactory makes seq node childList (via node)

6 Etomica  Application Programming Interface (API) Library of components used to assemble a simulation Can be used independent of development environment Invoked in code programmed using Emacs (for example)  GUI-based development environment Simulation is constructed by piecing together elements No programming required Result can be exported to run stand-alone as applet or application  Written in Java Widely used and platform independent Features of a modern programming language Object-oriented  Vehicle for presentation of molecular simulation methods

7 Etomica API Simulation Controller Species Phase Boundary Configuration Potential Meter Integrator SimulationGraphic Display Device Space Vector, Tensor Coordinate, Orientation

8 Simulation Elements: SimulationSimulation  Simulation collects all the other elements of the simulation and ensures that they are connected for proper interaction  There is only one instance of a Simulation in any applet/application Applet: runs in a web page Application: runs as a program, from command line  SimulationGraphic Subclass of Simulation used when preparing a simulation with a graphical user interface (GUI)

9 Simulation Elements: SpaceSpace  Space defines properties of the physical space in which the simulation is performed Dimensionality (1D, 2D, 3D, etc.); continuum vs. lattice Construction of vectors, tensors Makes Coordinate for placement in each Atom position and momentum vector CoordinatePair defines how distances are computed Constructs various types of Boundary for placement in each Phase  Concrete classes Space1D Space2D Space3D

10 Simulation Elements: ControllerController  Governs general plan of action for simulation For example: run forever, as controlled by an interactive Stop/Resume button run a fixed number of relaxation/production cycles, then quit run over a series of state conditions for a fixed duration at each  Oversees activities of Integrator Makes connections between Integrator and other elements to ensure proper functioning Turns Integrator on and off according to plan of action Initialization Reset block sums Compute final results blocks per simulation Entire Simulation New configuration 1 move per cycle cycles per block Add to block sum Compute block average Initialization Reset block sums Compute final results blocks per simulation Entire Simulation New configuration 1 move per cycle cycles per block Add to block sum Compute block average Initialization Reset block sums Compute final results blocks per simulation Entire Simulation New configuration 1 move per cycle cycles per block Add to block sum Compute block average

11 Simulation Elements: IntegratorIntegrator  Adds the physics needed to generate configurations properly various integration schemes introduced by developing a new integrator Molecular dynamics integrators hard-potential dynamics various kinds of soft-potential integrator Monte Carlo integrators more later  Places an Agent in each atom to assist integration for example, hard potential places Agent recording collision time collision partner  Fires IntegrationIntervalEvent to notify listeners that simulation has proceeded one step

12 Simulation Elements: IntegratorIntegrator  run method for top-level Integrator class public void run() { stepCount = 0; int iieCount = interval+1; while(stepCount < maxSteps) { while(pauseRequested) doWait(); if(resetRequested) {doReset(); resetRequested = false;} if(haltRequested) break; doStep(); //abstract method in Integrator. subclasses implement algorithms (MD/MC) if(--iieCount == 0) { //count down to determine when a cycle is completed fireIntervalEvent(intervalEvent); //notify listeners of completion of cycle iieCount = interval; } if(doSleep) { //slow down simulation so display can keep up try { Thread.sleep(sleepPeriod); } catch (InterruptedException e) { } } stepCount++; } //end of while loop fireIntervalEvent(new IntervalEvent(this, IntervalEvent.DONE)); } //end of run method

13 Simulation Elements: PhasePhase  Collects molecules that interact holds root of hierarchy of atoms/molecules handles addition/removal of molecules multiple phases possible in one simulation sets up base lists of all atoms, molecules, species defines which atoms are up or down from a given atom  Holds a Boundary object (from Space) that defines the boundary conditions used in the phase  Houses Configuration object that creates or saves a configuration of molecules

14 Simulation Elements: MeterMeter  Measurement of simulation property Configurational property in a phase potential energy kinetic energy density structure Each phase has by default kinetic and potential energy meters others added as desired Can also keep track of other quantities of interest simulation time  Accumulator handles all block averaging and error analysis listener for IntegrationIntervalEvent

15 Simulation Elements: SpeciesSpecies  Holds AtomFactory that defines how a particular type of molecule is constructed how many atoms of which type nominal arrangement of atoms in molecule  Places SpeciesAgent in each phase to manage molecules there root of atom hierarchy for species in phase looping over molecules addition and removal of atoms  Basis for defining interaction potential between molecules but does not by itself describe the pair potential

16 Simulation Elements: PotentialPotential  Defines interaction between atoms (and thereby molecules) Hard potential collision time collision dynamics Soft potential force, virial All potentials energy  Intermolecular potentials collect interatomic potential Potential1: intramolecular Potential2: intermolecular  Hierarchical arrangement More later

17 Simulation Elements: DisplayDisplay  Presents information from the simulation display of configuration for animation display of data table graph  Connects to Meter to get information  Listener of IntegrationIntervalEvent

18 Simulation Elements: Device  Interactive manipulation of simulation sliders, buttons, comboBoxes etc. for setting properties and affecting course of simulation

19 Putting It Together import etomica.*; public class MySimulation extends SimulationGraphic { //Constructor public void init() { //Instantiate classes super(Space2D()); controller = new Controller (this); integrator = new IntegratorHard(this); potential = new P2HardSphere(this); species = new SpeciesSpheresMono(this); phase = new Phase(this); display = new DisplayPhase(this); //Tie elements together this.elementCoordinator.go(); } //End of constructor public static void main(String[] args) { MySimulation simulation = new MySimulation(); simulation.makeAndDisplayFrame(); } //End of main } //End of MySimulation class

20 Running It  Compile source javac filename filename.java is the source file filename should be the same as the class defined in the file creates filename.class  Run as an applet for class named Applet1 Applet HTML need to reference etomica.jar, which contains simulation classesetomica.jar Load html in browser Enjoy your applet!  Run as an application java filename