http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/IMonitor.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/IMonitor.java b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/IMonitor.java new file mode 100644 index 0000000..133ca5c --- /dev/null +++ b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/IMonitor.java @@ -0,0 +1,37 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.monitor; + +import java.io.IOException; +import java.nio.file.Path; + +public interface IMonitor { + + /** + * Start directory monitoring + */ + public void startMonitor(Path path) throws IOException; + + /** + * Stop directory monitoring + */ + public void stopMonitor(); +}
http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/LocalFileSystemMonitor.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/LocalFileSystemMonitor.java b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/LocalFileSystemMonitor.java new file mode 100644 index 0000000..68121d6 --- /dev/null +++ b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/LocalFileSystemMonitor.java @@ -0,0 +1,261 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.monitor.impl; + +import org.apache.airavata.datacat.agent.dispatcher.DispatcherService; +import org.apache.airavata.datacat.agent.monitor.IMonitor; +import org.apache.airavata.datacat.agent.util.AgentProperties; +import org.apache.airavata.datacat.agent.util.Constants; +import org.apache.airavata.datacat.models.OutputMonitorMessage; +import org.apache.airavata.datacat.models.OutputMonitorMessageType; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import static java.nio.file.StandardWatchEventKinds.*; + +/** + * This monitor is specifically targeting the GridChem use case + */ + +public class LocalFileSystemMonitor implements IMonitor { + + private final Logger logger = LogManager.getLogger(LocalFileSystemMonitor.class); + private final WatchService watcher; + private final Map<WatchKey, Path> keys; + private boolean runMonitor = false; + private boolean trace = false; + private long waitTime; + + private ArrayList<OutputInfo> snapshot; + private String serialisedFileName = "snapshot.ser"; + + private DispatcherService dispatcherService; + + public LocalFileSystemMonitor() throws Exception { + this.watcher = FileSystems.getDefault().newWatchService(); + this.keys = new HashMap<WatchKey, Path>(); + waitTime = Integer.parseInt( + AgentProperties.getInstance().getProperty(Constants.BATCH_MONITOR_WAIT_TIME, "1000")); + dispatcherService = DispatcherService.getInstance(); + + runMonitor = false; + if ((new File(serialisedFileName)).exists()) { + snapshot = (ArrayList<OutputInfo>) (new ObjectInputStream(new FileInputStream(serialisedFileName))).readObject(); + } else { + + logger.info("Starting Batch Monitor Scan..."); + + ArrayList<OutputInfo> currentFiles = getCurrentFilesList( + getCurrentFilesMap(AgentProperties.getInstance().getProperty(Constants.DATA_ROOT, ""))); + + ArrayList<OutputMonitorMessage> outputMonitorMessages = new ArrayList<OutputMonitorMessage>(); + for (int i = 0; i < currentFiles.size(); i++) { + OutputMonitorMessage fileWatcherMessage = new OutputMonitorMessage(); + //fileWatcherMessage.setOutputPath(currentFiles.get(i).getOutputName()); + fileWatcherMessage.setOutputPath(currentFiles.get(i).getOutputPath()); + fileWatcherMessage.setFileMonitorMessageType(OutputMonitorMessageType.FILE_CREATED); + + outputMonitorMessages.add(fileWatcherMessage); + } + + logger.info("Ending Batch Monitor Scan..."); + + for (int i = 0; i < outputMonitorMessages.size(); i++) { + logger.info("Adding file monitor message for "+ outputMonitorMessages.get(i).getOutputPath()); + dispatcherService.addFileMonitorMessage(outputMonitorMessages.get(i)); + } + + ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(serialisedFileName)); + outputStream.writeObject(currentFiles); + this.snapshot = currentFiles; + } + } + + /** + * Start directory monitoring + */ + @Override + public void startMonitor(Path path) throws IOException { + init(path); + runMonitor = true; + processEvents(); + logger.info("Started directory watching"); + } + + /** + * Stop directory monitoring + */ + @Override + public void stopMonitor() { + runMonitor = false; + logger.info("Stopped directory watching"); + } + + /** + * Initializing the FileSystemMonitor + * + * @param path + * @throws java.io.IOException + */ + private void init(Path path) throws IOException { + this.trace = false; + + logger.info("Scanning " + path); + registerAll(path); + logger.info("Done."); + + // enable trace after initial registration + this.trace = true; + + } + + /** + * Register the given directory with the WatchService + */ + private void register(Path dir) throws IOException { + WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); + if (trace) { + Path prev = keys.get(key); + if (prev == null) { + logger.info("register: " + dir); + } else { + if (!dir.equals(prev)) { + logger.info("update: " + prev + " -> " + dir); + } + } + } + keys.put(key, dir); + } + + /** + * Register the given directory, and all its sub-directories, with the + * WatchService. + */ + private void registerAll(final Path start) throws IOException { + // register directory and sub-directories + Files.walkFileTree(start, new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) + throws IOException { + register(dir); + return FileVisitResult.CONTINUE; + } + }); + } + + /** + * Processing directory update events + */ + @SuppressWarnings("unchecked") + private void processEvents() { + (new Thread(new Runnable() { + @Override + public void run() { + while (runMonitor) { + try { + logger.info("Starting Batch Monitor Scan..."); + Thread.sleep(waitTime); + HashMap<String, OutputInfo> currentFilesMap = getCurrentFilesMap( + AgentProperties.getInstance().getProperty(Constants.DATA_ROOT, "")); + ArrayList<OutputInfo> currentFilesList = getCurrentFilesList(currentFilesMap); + ArrayList<OutputMonitorMessage> outputMonitorMessages = new ArrayList<OutputMonitorMessage>(); + for (int i = 0; i < snapshot.size(); i++) { + OutputInfo fSnap = snapshot.get(i); + OutputInfo fCurrent = currentFilesMap.get(fSnap.getOutputPath()); + if (fCurrent == null) { + OutputMonitorMessage fileWatcherMessage = new OutputMonitorMessage(); + fileWatcherMessage.setOutputPath(fSnap.getOutputName()); + fileWatcherMessage.setOutputPath(fSnap.getOutputPath()); + fileWatcherMessage.setFileMonitorMessageType(OutputMonitorMessageType.FILE_DELETED); + outputMonitorMessages.add(fileWatcherMessage); + } else { + if (fSnap.getLastModifiedTime() != fCurrent.getLastModifiedTime()) { + OutputMonitorMessage fileWatcherMessage = new OutputMonitorMessage(); + fileWatcherMessage.setOutputPath(fSnap.getOutputName()); + fileWatcherMessage.setOutputPath(fSnap.getOutputPath()); + fileWatcherMessage.setFileMonitorMessageType(OutputMonitorMessageType.FILE_MODIFIED); + outputMonitorMessages.add(fileWatcherMessage); + } + currentFilesMap.remove(fSnap.getOutputPath()); + } + } + ArrayList<OutputInfo> newlyCreatedFiles = new ArrayList<OutputInfo>(currentFilesMap.values()); + for (int i = 0; i < newlyCreatedFiles.size(); i++) { + OutputInfo fNew = newlyCreatedFiles.get(i); + OutputMonitorMessage outputMonitorMessage = new OutputMonitorMessage(); + outputMonitorMessage.setOutputPath(fNew.getOutputName()); + outputMonitorMessage.setOutputPath(fNew.getOutputPath()); + outputMonitorMessage.setFileMonitorMessageType(OutputMonitorMessageType.FILE_MODIFIED); + outputMonitorMessages.add(outputMonitorMessage); + } + logger.info("Ending Batch Monitor Scan..."); + + for (int i = 0; i < outputMonitorMessages.size(); i++) { + logger.info("Adding file monitor message for "+ outputMonitorMessages.get(i).getOutputPath()); + dispatcherService.addFileMonitorMessage(outputMonitorMessages.get(i)); + } + + + ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(serialisedFileName)); + outputStream.writeObject(currentFilesList); + + logger.info("Successfully serialized new directory snapshot..."); + snapshot = currentFilesList; + + } catch (InterruptedException e) { + logger.error(e.toString()); + } catch (IOException e){ + logger.error(e.toString()); + } + } + } + })).start(); + } + + private HashMap<String, OutputInfo> getCurrentFilesMap(String path) { + HashMap<String, OutputInfo> currentFiles = new HashMap<String, OutputInfo>(); + File root = new File(path); + File[] list = root.listFiles(); + + if (list == null) return currentFiles; + + for (File f : list) { + if (f.isDirectory()) { + OutputInfo newOutputInfo = new OutputInfo(f.getName(), f.getPath(), f.lastModified()); + currentFiles.put(f.getPath(), newOutputInfo); + } + } + + return currentFiles; + } + + private ArrayList<OutputInfo> getCurrentFilesList(HashMap<String, OutputInfo> currentFilesMap) { + ArrayList<OutputInfo> currentFiles = new ArrayList<OutputInfo>(currentFilesMap.values()); + return currentFiles; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/OutputInfo.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/OutputInfo.java b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/OutputInfo.java new file mode 100644 index 0000000..0b3ed14 --- /dev/null +++ b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/monitor/impl/OutputInfo.java @@ -0,0 +1,62 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.monitor.impl; + +import java.io.Serializable; + +public class OutputInfo implements Serializable { + + private String outputName; + + private String outputPath; + + private long lastModifiedTime; + + public OutputInfo(String outputName, String outputPath, long lastModified) { + this.outputName = outputName; + this.outputPath = outputPath; + this.lastModifiedTime = lastModified; + } + + public String getOutputName() { + return outputName; + } + + public void setOutputName(String outputName) { + this.outputName = outputName; + } + + public String getOutputPath() { + return outputPath; + } + + public void setOutputPath(String outputPath) { + this.outputPath = outputPath; + } + + public long getLastModifiedTime() { + return lastModifiedTime; + } + + public void setLastModifiedTime(long lastModified) { + this.lastModifiedTime = lastModified; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/AgentProperties.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/AgentProperties.java b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/AgentProperties.java new file mode 100644 index 0000000..f51403b --- /dev/null +++ b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/AgentProperties.java @@ -0,0 +1,75 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.util; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import java.io.*; + +public class AgentProperties { + + public static final String AGENT_PROPERTY_FILE = "../conf/agent.properties"; + public static final String DEFAULT_AGENT_PROPERTY_FILE = "conf/agent.properties"; + + private static AgentProperties instance; + + private final Logger logger = LogManager.getLogger(AgentProperties.class); + private java.util.Properties properties = null; + + private AgentProperties() { + try { + InputStream fileInput; + if (new File(AGENT_PROPERTY_FILE).exists()) { + fileInput = new FileInputStream(AGENT_PROPERTY_FILE); + logger.info("Using configured agent property (agent.properties) file"); + } else { + logger.info("Using default agent property (agent.properties) file"); + fileInput = ClassLoader.getSystemResource(DEFAULT_AGENT_PROPERTY_FILE).openStream(); + } + java.util.Properties properties = new java.util.Properties(); + properties.load(fileInput); + fileInput.close(); + this.properties = properties; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static AgentProperties getInstance() { + if (instance == null) { + instance = new AgentProperties(); + } + return instance; + } + + public String getProperty(String key, String defaultVal) { + String val = this.properties.getProperty(key); + + if (val.isEmpty() || val == "") { + return defaultVal; + } else { + return val; + } + } +} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/Constants.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/Constants.java b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/Constants.java new file mode 100644 index 0000000..50089ce --- /dev/null +++ b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/Constants.java @@ -0,0 +1,56 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.util; + +public class Constants { + public static final String DATA_ROOT = "DATA_ROOT"; + + public static final String FILE_UPDATE_MESSAGE_DELAY = "FILE_UPDATE_MESSAGE_DELAY"; + + public static final String MAX_PARSER_THREADS = "MAX_PARSER_THREADS"; + + public static final String BATCH_MONITOR_WAIT_TIME = "BATCH_MONITOR_WAIT_TIME"; + + public static final String PUBLISHER_ADD_ENDPOINT = "PUBLISHER_ADD_ENDPOINT"; + + public static final String FILE_INFO_QUEUE_NAME = "FILE_INFO_QUEUE_NAME"; + + public static final String MONITOR_TYPE = "MONITOR_TYPE"; + + public static final String RABBITMQ_HOST = "RABBITMQ_HOST"; + + public static final String BINDING_KEY = "BINDING_KEY"; + + public static final String EXCHANGE_NAME = "EXCHANGE_NAME"; + + public static final String PARSER_CLASS = "PARSER_CLASS"; + + public static final String ZK_HOST = "ZK_HOST"; + + public static final String KEYSTORE_FILE = "KEYSTORE_FILE"; + + public static final String KEYSTORE_PWD = "KEYSTORE_PWD"; + + public static final String TRUSTSTORE_FILE = "TRUSTSTORE_FILE"; + + public static final String TRUSTSTORE_PWD = "TRUSTSTORE_PWD"; + +} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/ThriftUtils.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/ThriftUtils.java b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/ThriftUtils.java new file mode 100644 index 0000000..b165aab --- /dev/null +++ b/datacat/agent/src/main/java/org/apache/airavata/datacat/agent/util/ThriftUtils.java @@ -0,0 +1,37 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.datacat.agent.util; + +import org.apache.thrift.TBase; +import org.apache.thrift.TDeserializer; +import org.apache.thrift.TException; +import org.apache.thrift.TSerializer; + +public class ThriftUtils { + public static byte[] serializeThriftObject(TBase object) throws TException { + return new TSerializer().serialize(object); + } + + public static void createThriftFromBytes(byte []bytes, TBase object) throws TException { + new TDeserializer().deserialize(object, bytes); + } +} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/resources/bin/datacat-agent.sh ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/resources/bin/datacat-agent.sh b/datacat/agent/src/main/resources/bin/datacat-agent.sh new file mode 100644 index 0000000..12f5cee --- /dev/null +++ b/datacat/agent/src/main/resources/bin/datacat-agent.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +. `dirname $0`/setenv.sh +cd $DATACAT_AGENT_HOME + +IS_DAEMON_MODE=false +DATACAT_AGENT_COMMAND="" +STOP=false +FORCE=false + +for var in "$@" +do + case $var in + start) + IS_DAEMON_MODE=true + shift + ;; + stop) + STOP=true + DATACAT_SERVER_COMMAND="$ + DATACAT_AGENT_COMMAND $var" + shift + ;; + -h) + echo "Usage: datacat-agent.sh [command-options]" + echo "command options:" + echo " start Start agent in daemon mode" + echo " stop Stop server." + echo " -h Display this help and exit" + shift + exit 0 + ;; + *) + DATACAT_SERVER_COMMAND="$DATACAT_AGENT_COMMAND $var" + shift + esac +done + +if $STOP; +then + for f in `find . -name "*-start_*"`; do + IFS='_' read -a f_split <<< "$f" + echo "Found process file : $f" + echo -n " Sending kill signals to process ${f_split[1]}..." + out=`kill -9 ${f_split[1]} 2>&1` + if [ -z "$out" ]; then + echo "done" + else + echo "failed (REASON: $out)" + fi + echo -n " Removing process file..." + out=`rm $f 2>&1` + if [ -z "$out" ]; then + echo "done" + else + echo "failed (REASON: $out)" + fi + done +else + if $IS_DAEMON_MODE ; then + echo "Starting DataCat agent in daemon mode..." + cd "$DATACAT_AGENT_HOME"/lib + nohup $JAVA_HOME/bin/java -jar agent-1.0-SNAPSHOT.jar > ../datacat-agent.out & echo $! > "../agent-start_$!" + else + cd "$DATACAT_AGENT_HOME"/lib + $JAVA_HOME/bin/java -jar agent-1.0-SNAPSHOT.jar & echo $! > "agent-start_$!" + fi +fi \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/resources/bin/setenv.sh ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/resources/bin/setenv.sh b/datacat/agent/src/main/resources/bin/setenv.sh new file mode 100644 index 0000000..724c51f --- /dev/null +++ b/datacat/agent/src/main/resources/bin/setenv.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Get standard environment variables +# if JAVA_HOME is not set we're not happy +if [ -z "$JAVA_HOME" ]; then + echo "You must set the JAVA_HOME variable before running datacat-server scripts." + exit 1 +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false +os400=false +case "`uname`" in +CYGWIN*) cygwin=true;; +OS400*) os400=true;; +esac + +# resolve links - $0 may be a softlink +PRG="$0" + +while [ -h "$PRG" ]; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '.*/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +PRGDIR=`dirname "$PRG"` + +# Only set DATACAT_AGENT_HOME if not already set +[ -z "$DATACAT_AGENT_HOME" ] && DATACAT_AGENT_HOME=`cd "$PRGDIR/.." ; pwd` + +DATACAT_AGENT_CLASSPATH="" + + + +for f in "DATACAT_AGENT_HOME"/lib/*.jar +do + DATACAT_AGENT_CLASSPATH="$DATACAT_AGENT_CLASSPATH":$f +done + +DATACAT_AGENT_CLASSPATH="$DATACAT_AGENT_CLASSPATH":"$DATACAT_AGENT_HOME"/conf/log4j.properties + +export DATACAT_AGENT_HOME +export DATACAT_AGENT_CLASSPATH \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/resources/conf/agent.properties ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/resources/conf/agent.properties b/datacat/agent/src/main/resources/conf/agent.properties new file mode 100644 index 0000000..5c8f3d3 --- /dev/null +++ b/datacat/agent/src/main/resources/conf/agent.properties @@ -0,0 +1,44 @@ +#Max parser threads +MAX_PARSER_THREADS=1000 + +#Wait time for the local file system bath monitor +BATCH_MONITOR_WAIT_TIME=2000 + +#file update delay time for the local file system batch monitor +FILE_UPDATE_MESSAGE_DELAY=5 + +#Metadata publisher end point +PUBLISHER_ADD_ENDPOINT=https://192.168.0.4:8888/publisher/addFileMetadata/ + +#Monitor type is FILE_SYSTEM or RABBITMQ +MONITOR_TYPE=RABBITMQ + +#Data Root for the local file system scanner +DATA_ROOT=/home/supun/datacat/data_root + +#Rabbitmq file info message queue +FILE_INFO_QUEUE_NAME=file_info_queue + +#RabbitMQ host name +RABBITMQ_HOST=localhost + +#Binding key for the RabbitMQ queue +BINDING_KEY=* + +#RabbitMQ Exchange Name +EXCHANGE_NAME=datacat + +PARSER_CLASS=org.apache.airavata.datacat.parsers.gridchem.GridChemDemoParser +#PARSER_CLASS=org.apache.airavata.datacat.regexParser.RegexParser + +#Security Specific Configurations +KEYSTORE_FILE=keystore.jks + +KEYSTORE_PWD=wso2carbon + +TRUSTSTORE_FILE=client-truststore.jks + +TRUSTSTORE_PWD=wso2carbon + +#Zookeeper Host Name +ZK_HOST=localhost \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/resources/log4j.properties b/datacat/agent/src/main/resources/log4j.properties new file mode 100644 index 0000000..f0a97e9 --- /dev/null +++ b/datacat/agent/src/main/resources/log4j.properties @@ -0,0 +1,16 @@ +#CONSOLE AND FILE LOGGING +#CONSOLE LOGGING +log4j.rootLogger=ALL, CONSOLE +log4j.logger.console=WARN, CONSOLE +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n +log4j.appender.CONSOLE.Threshold=DEBUG + +#FILE LOGGING +log4j.logger.file=ALL, DAILYROLLINGFILEAPPENDER +log4j.appender.DAILYROLLINGFILEAPPENDER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DAILYROLLINGFILEAPPENDER.layout=org.apache.log4j.PatternLayout +log4j.appender.DAILYROLLINGFILEAPPENDER.layout.ConversionPattern=%d [%t] %-5p %c - %m%n +log4j.appender.DAILYROLLINGFILEAPPENDER.File=/tmp/datacat-agent.log +log4j.appender.DAILYROLLINGFILEAPPENDER.Threshold=ALL \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/resources/security/client-truststore.jks ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/resources/security/client-truststore.jks b/datacat/agent/src/main/resources/security/client-truststore.jks new file mode 100644 index 0000000..be441f3 Binary files /dev/null and b/datacat/agent/src/main/resources/security/client-truststore.jks differ http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/main/resources/security/keystore.jks ---------------------------------------------------------------------- diff --git a/datacat/agent/src/main/resources/security/keystore.jks b/datacat/agent/src/main/resources/security/keystore.jks new file mode 100644 index 0000000..7942c53 Binary files /dev/null and b/datacat/agent/src/main/resources/security/keystore.jks differ http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQConsumerTest.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQConsumerTest.java b/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQConsumerTest.java new file mode 100644 index 0000000..8cdec43 --- /dev/null +++ b/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQConsumerTest.java @@ -0,0 +1,124 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.org.apache.airavata.datacat.agent.messageBroker; + +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; +import org.apache.airavata.datacat.agent.messageBroker.AiravataUpdateListener; +import org.apache.airavata.datacat.agent.messageBroker.IMessageBroker; +import org.apache.airavata.datacat.agent.util.AgentProperties; +import org.apache.airavata.datacat.agent.util.Constants; +import org.apache.airavata.datacat.agent.util.ThriftUtils; +import org.apache.airavata.datacat.models.Messaging.ExperimentOutputCreatedEvent; +import org.apache.airavata.datacat.models.Messaging.Message; +import org.apache.airavata.datacat.models.Messaging.MessageType; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.junit.Before; +import org.junit.Test; + + +public class RabbitMQConsumerTest { + + private static final Logger logger = LogManager.getLogger(RabbitMQConsumerTest.class); + + private final String RABBITMQ_HOST = AgentProperties.getInstance().getProperty(Constants.RABBITMQ_HOST, ""); + private final String EXCHANGE_NAME = AgentProperties.getInstance().getProperty(Constants.EXCHANGE_NAME, ""); + private final String BINDING_KEY = AgentProperties.getInstance().getProperty(Constants.BINDING_KEY, ""); + + private IMessageBroker messageBroker; + + /** + * RabbitMQ server should be started to run this test + */ + @Before + public void init() { + //start the RabbitMQConsumer + messageBroker = new AiravataUpdateListener(); + try { + messageBroker.startBroker(); + logger.info("Started Message Broker!!!"); + Thread.sleep(4000); + } catch (Exception e) { + logger.error("Exception occured while starting the message broker!! " + e); + } + } + + @Test + public void testRabbitMQConsumer() { + try { + //publish test data + publish(MessageType.EXPERIMENT_OUTPUT); + + //wait for the consumer to recieve the message + Thread.sleep(4000); + } catch (Exception e) { + logger.error(e); + } + messageBroker.stopBroker(); + } + + /** + * Test method to publish dummy data to RabbitMQ + * @param messageType + * @throws java.io.IOException + * @throws TException + */ + public void publish(MessageType messageType) + throws java.io.IOException, TException { + + //establishing the connection + ConnectionFactory factory = new ConnectionFactory(); + factory.setHost(RABBITMQ_HOST); + Connection connection = factory.newConnection(); + Channel channel = connection.createChannel(); + + channel.exchangeDeclare(EXCHANGE_NAME, "topic"); + + String DATA_ROOT = AgentProperties.getInstance().getProperty(Constants.DATA_ROOT, ""); + + //creating the output created Event + ExperimentOutputCreatedEvent event = new ExperimentOutputCreatedEvent(); + event.setExperimentId("test"); + event.setOutputPath(DATA_ROOT + "/2H2OOHNCmin.com.out"); + + //serializing the event + byte[] body = ThriftUtils.serializeThriftObject(event); + Message message = new Message(); + message.setEvent(body); + message.setMessageId("sad"); + message.setMessageType(messageType); + message.setUpdatedTime(993344232); + String routingKey = "*"; + + //serializing the message object + byte[] messageArray = ThriftUtils.serializeThriftObject(message); + channel.basicPublish(EXCHANGE_NAME, BINDING_KEY, null, messageArray); + + logger.debug(" [x] Sent '" + message + "'"); + + channel.close(); + connection.close(); + } + +} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQPublisherTest.java ---------------------------------------------------------------------- diff --git a/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQPublisherTest.java b/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQPublisherTest.java new file mode 100644 index 0000000..539b452 --- /dev/null +++ b/datacat/agent/src/test/java/org/apache/airavata/datacat/agent/org/apache/airavata/datacat/agent/messageBroker/RabbitMQPublisherTest.java @@ -0,0 +1,78 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +package org.apache.airavata.datacat.agent.org.apache.airavata.datacat.agent.messageBroker; + +import org.apache.airavata.datacat.agent.messageBroker.AiravataUpdateListener; +import org.apache.airavata.datacat.agent.messageBroker.IMessageBroker; +import org.apache.airavata.datacat.agent.messageBroker.RabbitMQPublisher; +import org.apache.airavata.datacat.models.Messaging.ExperimentOutputParsedEvent; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.junit.Before; +import org.junit.Test; + +public class RabbitMQPublisherTest { + private static final Logger logger = LogManager.getLogger(RabbitMQPublisherTest.class); + + private RabbitMQPublisher rabbitMQPublisher; + private IMessageBroker messageBroker; + + @Before + public void setup() { + try { + rabbitMQPublisher = new RabbitMQPublisher(); + logger.info("Started the RabbitMQPublisher"); + + //start the RabbitMQConsumer + messageBroker = new AiravataUpdateListener(); + messageBroker.startBroker(); + logger.info("Started Message Broker!!!"); + Thread.sleep(4000); + + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testRabbitMQPublisher() { + rabbitMQPublisher.publish(getDummyOutputParsedEvent()); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + logger.error(e); + }finally { + messageBroker.stopBroker(); + } + } + + /** + * a test method to return dummy data + * @return ExperimentOutputParsedEvent + */ + public ExperimentOutputParsedEvent getDummyOutputParsedEvent() { + ExperimentOutputParsedEvent experimentOutputParsedEvent = new ExperimentOutputParsedEvent(); + experimentOutputParsedEvent.setExperimentId("3343243234"); + experimentOutputParsedEvent.setStatus("success"); + experimentOutputParsedEvent.setDocumentID("sadas3qe34"); + return experimentOutputParsedEvent; + } +} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/B3PW91.cup ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/B3PW91.cup b/datacat/cup_flex/B3PW91.cup new file mode 100644 index 0000000..d601fa9 --- /dev/null +++ b/datacat/cup_flex/B3PW91.cup @@ -0,0 +1,166 @@ +import java_cup.runtime.*; +import javax.swing.*; +import java.util.*; +import java.io.*; + + + +/* +OUTPUT FORMAT:____________________________________________________________ +1NSERCH= 0 + more text + SCF Done: E(RB+HF-PW91)= -7.85284496695 A.U. after 8 cycles + more text + Maximum Force 0.000000 0.000450 YES + RMS Force 0.000000 0.000300 YES + more text +TO MONITOR:____________________________________________________________ + iteration, energy + +MANUALLY ADD TO CUP-GENERATED CLASS IN SCFaParser.java:________________ + + +//add to CUP$SCFaParser$actions +public ParseSCF2 parseSCF; + +//add to the constructor of CUP$SCFaParser$actions + parseSCF = new ParseSCF2(); + +*/ + +action code {: + //__________________________________ + public static boolean DEBUG = true; + private static JTable table; + private static final String tableLabel = "SCF Intermediate Results:"; +// private static String cycle = "0"; + + + public static JTable getTable() { + return table; + } + + public static String getTableLabel() { + return tableLabel; + } + +// } +:} + + + + +terminal FOUNDITER1, SCFDONE1, NSearch1, Energ1, MaxGrad1, RmsGrad1; +terminal MPStart, NMP, MPEnerg, MPMax, MPRms, MPDONE; +terminal Integer ITERATION1, MPITER; +terminal Float ENERGY1, MGRAD1, RGRAD1, MPENERGY, MPMGRAD, MPRGRAD; +non terminal startpt, scfintro, scfpat, scfcycle, cycle, grad1, grad2; +non terminal mp2, mpintro, mppat, mpcycle, mpcycle1, force1, force2; + + + +/* ___________ + The grammer */ + +startpt ::= scfintro + scfpat + SCFDONE1 + mp2 + MPDONE + {: if (DEBUG) System.out.println("CUP:gopt: end of parse tree "); + :} + ; + + + + +scfintro ::= + FOUNDITER1 + {: if (DEBUG) System.out.println("CUP:gopt: found the start of Iteration"); :} +; + +scfpat ::= scfpat scfcycle + {: if (DEBUG) System.out.println("CUP:gopt: in scfpat"); :} + | + scfcycle +// Originally: SCFDONE1 +; + +scfcycle ::= Energ1 ENERGY1:e +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: ENERGY "+e); + :} +cycle +; + + + + +cycle ::= NSearch1 ITERATION1:c +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: ITERATION "+c); + :} +grad1 +grad2 + ; + +grad1 ::= MaxGrad1 MGRAD1:mg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: Maximum Force "+mg); + :} +; + +grad2 ::= RmsGrad1 RGRAD1:rg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: RMS Force "+rg); + :} +; + +mp2 ::= mpintro mppat +{: + if (DEBUG) System.out.println("CUP:g1: in mp2 mpintro mppat"); + :} +; + +mpintro ::= +MPStart +{: + if (DEBUG) System.out.println("CUP:g1: MPSTart "); + :} +; + +mppat ::= mppat mpcycle1 +{: + if (DEBUG) System.out.println("CUP:g1: in mppat"); + :} +| +mpcycle1 +; + +mpcycle1 ::= MPEnerg MPENERGY:mpen +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: ENERGY "+mpen); + :} +mpcycle +; + + +mpcycle ::= NMP MPITER:it +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: MP ITERATION "+it); + :} +force1 +force2 +; + +force1 ::= MPMax MPMGRAD:mpmg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: MP Maximum Force "+mpmg); + :} +; + +force2 ::= MPRms MPRGRAD:mprg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: MP RMS Force "+mprg); + :} +; http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/B3PW91.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/B3PW91.flex b/datacat/cup_flex/B3PW91.flex new file mode 100644 index 0000000..d988603 --- /dev/null +++ b/datacat/cup_flex/B3PW91.flex @@ -0,0 +1,204 @@ +Fimport java_cup.runtime.*; + +%% + +%class B3PW91Lexer +%public +%unicode +%cup +%cupdebug +%state ITER +%state ITER2 +%state ITER3 +%state INTVALUE +%state FLOATVALUE +%state FLOAT1 +%state FLOAT2 +%state MP2 +%state MPOPT +%state FLOATMP1 +%state FLOATMP2 +%state FLOATMP3 +%state IGNOREALL +%state INTMP +%standalone +%8bit + +/* ___________________________________________ + Copied verbatim into generated lexer class: +*/ +%{ + public static boolean DEBUG = false; +%} + +LineTerminator = \r|\n|\r\n +InputCharacter = [^\r\n] +WhiteSpace = {LineTerminator} | [ \t\f] +Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} +TraditionalComment = "/*" [^*] ~"*/" +EndOfLineComment = "//" {InputCharacter}* {LineTerminator} +DocumentationComment = "/**" {CommentContent} "*"+ "/" +CommentContent = ( [^*] | \*+ [^/*] )* /* adjust syntax font-coloring */ +Identifier = [:jletter:] [:jletterdigit:]* +dec_int_lit = 0 | [1-9][0-9]* +dec_int_id = [A-Za-z_][A-Za-z_0-9]* +DIGIT = [0-9] +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}+ +INT = [+|-]?{DIGIT}+ +BOOL = [T|F] +EQ = "=" +STRING = [A-Z]+ +GRAB = [^(" "|\r|\n|\r\n| \t\f)]+ + +%% + +<YYINITIAL>{ + "Number of steps in this run" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found Number of steps"); + yybegin(ITER); + return new Symbol(B3Pw91Sym.FOUNDITER1); + } +} + +<ITER>{ + "Step number" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found the Step number"); + yybegin(INTVALUE); + return new Symbol(B3Pw91Sym.NSearch1);} + + "SCF Done: E(RB+HF-PW91) =" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found the energy in ITER"); + yybegin(FLOATVALUE); + return new Symbol(B3Pw91Sym.Energ1);} + + "Maximum Force" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found Maximum Force"); + yybegin(FLOAT1); + return new Symbol(B3Pw91Sym.MaxGrad1);} + + "RMS Force" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found RMS Force"); + yybegin(FLOAT2); + return new Symbol(B3Pw91Sym.RmsGrad1);} + + + "Optimization completed" { +if (Settings.DEBUG) System.out.println("B3PW91Flex: SCFDONE1, Optimization completed"); + yybegin(MP2); + return new Symbol(B3Pw91Sym.SCFDONE1);} + + .|\n {} + +} + + +<FLOATVALUE>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found the energy in FLOATVALUE"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITER); + return new Symbol(B3Pw91Sym.ENERGY1, new Float(yytext()));} +} + +<FLOAT1>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found the maximum force"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITER); + return new Symbol(B3Pw91Sym.MGRAD1, new Float(yytext()));} +} + +<FLOAT2>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found the RMS force"); +if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITER); + return new Symbol(B3Pw91Sym.RGRAD1, new Float(yytext()));} +} + +<INTVALUE>{ + {INT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found iteration"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin (ITER); + return new Symbol(B3Pw91Sym.ITERATION1, new Integer(yytext())); +} +} + +<MP2>{ + "MP2/6-31G(d') Opt=RCFC" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found MP2(Full)"); + yybegin(MPOPT); + return new Symbol(B3Pw91Sym.MPStart);} + } + + +<MPOPT>{ + + "Step number" { +if (Settings.DEBUG) System.out.println("B3PW91Flex: Found the Step number for MP"); + yybegin(INTMP); + return new Symbol(B3Pw91Sym.NMP);} + + "EUMP2 = " { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found MP2 energy"); + yybegin(FLOATMP1); + return new Symbol(B3Pw91Sym.MPEnerg);} + + "Maximum Force" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found Maximum Force"); + yybegin(FLOATMP2); + return new Symbol(B3Pw91Sym.MPMax);} + + "RMS Force" { + if (Settings.DEBUG) System.out.println("B3PW91Flex: Found RMS Force"); + yybegin(FLOATMP3); + return new Symbol(B3Pw91Sym.MPRms);} + + + "Optimization completed" { + yybegin(IGNOREALL); + return new Symbol(B3Pw91Sym.MPDONE);} + + + .|\n {} + } + + +<FLOATMP1>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: MP2 Found the energy"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(MPOPT); + return new Symbol(B3Pw91Sym.MPENERGY, new Float(yytext()));} +} + +<FLOATMP2>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: MP2 Found the maximum force"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(MPOPT); + return new Symbol(B3Pw91Sym.MPMGRAD, new Float(yytext()));} +} + +<FLOATMP3>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: MP2 Found the RMS force"); +if (Settings.DEBUG) System.out.println(yytext()); + yybegin(MPOPT); + return new Symbol(B3Pw91Sym.MPRGRAD, new Float(yytext()));} +} + +<INTMP>{ + {INT} { + if (Settings.DEBUG) System.out.println("B3PW91Flex: MP2 Found iteration"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin (MPOPT); + return new Symbol(B3Pw91Sym.MPITER, new Integer(yytext()));} +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/Makefile ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/Makefile b/datacat/cup_flex/Makefile new file mode 100644 index 0000000..158f3f3 --- /dev/null +++ b/datacat/cup_flex/Makefile @@ -0,0 +1,60 @@ +# GridChem CUP_FLEX Makefile. +# First order draft. Perhaps this will be replaced by ant. +# Scott Brozell, OSC, May 10, 2005 + +JAVA=java +JAVAC=javac +JAVA_CUP=java_cup +JAVA_CUP_MAIN=$(JAVA_CUP).Main +JAVA_CUP_PARENT_PATH=.. +JFLEX=JFlex +JFLEX_MAIN=$(JFLEX).Main +JFLEX_PARENT_PATH=.. +LEXER_CLASS_NAME_TAIL=Lexer +PARSER_CLASS_NAME_TAIL=Parser +SCANNER_PARSER_BASENAMES=whichProgram +SYMBOLS_CLASS_NAME_TAIL=Sym + +# This target builds all the parsers. +# It assumes that java_cup and JFlex are built, but they could be dependencies. +all: $(SCANNER_PARSER_BASENAMES) + +# This target builds the Java parser generator CUP. +java_cup: + cd $(JAVA_CUP_PARENT_PATH); \ + $(JAVAC) $(JAVA_CUP)/*.java $(JAVA_CUP)/runtime/*.java + +# This target builds the Java lexical analyzer generator JFlex. +# The java_cup runtime package is required; thus the classpath specification. +jflex: + cd $(JFLEX_PARENT_PATH); \ + $(JAVAC) -classpath . $(JFLEX)/*.java $(JFLEX)/gui/*.java + +# These targets build parsers by invoking CUP, via the method java_cup.Main. +# Note the annoying lack of consistency between file and class names. + +SCFa: scfaLexer scfaParserandSym + +whichProgram: WhichProgram + +WhichProgram: whichProgram.cup whichProgram.flex + $(JAVA) -classpath $(JAVA_CUP_PARENT_PATH) $(JAVA_CUP_MAIN) \ + -parser $@$(PARSER_CLASS_NAME_TAIL) \ + -symbols $@$(SYMBOLS_CLASS_NAME_TAIL) < whichProgram.cup + $(JAVA) -classpath $(JFLEX_PARENT_PATH) $(JFLEX_MAIN) whichProgram.flex + + +%$(LEXER_CLASS_NAME_TAIL): %.flex + $(JAVA) -classpath $(JFLEX_PARENT_PATH) $(JFLEX_MAIN) $< + +%$(PARSER_CLASS_NAME_TAIL)and$(SYMBOLS_CLASS_NAME_TAIL): %.cup + $(JAVA) -classpath $(JAVA_CUP_PARENT_PATH) $(JAVA_CUP_MAIN) \ + -parser $*$(PARSER_CLASS_NAME_TAIL) \ + -symbols $*$(SYMBOLS_CLASS_NAME_TAIL) < $< + +install: all + mv *.java ../GridChem/ + +clean: + -$(RM) *.java *.java~ + http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/casscf.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/casscf.flex b/datacat/cup_flex/casscf.flex new file mode 100644 index 0000000..68899f3 --- /dev/null +++ b/datacat/cup_flex/casscf.flex @@ -0,0 +1,237 @@ +/* CASSCF Keyword + Last Update: 6/26/2001 + http://www.gaussian.com/00000419.htm +*/ + + + +%% + + + +%class CASSCF +%public +%unicode +/* +%cup +%cupdebug +*/ +%ignorecase + +%state GETN +%state GETCOMMA +%state GETM +%state ITN +%state ITNFLOAT +%state FLOATVAL +%state INTVAL +%state IGNOREALL + +%standalone +%8bit +%{ + public static boolean DEBUG = false; +%} + +/* ______ + Macros */ +LineTerminator = \r|\n|\r\n +InputCharacter = [^\r\n] +WhiteSpace = {LineTerminator} | [ \t\f] + +/* ________ + Comments */ +Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} +TraditionalComment = "/*" [^*] ~"*/" +EndOfLineComment = "//" {InputCharacter}* {LineTerminator} +DocumentationComment = "/**" {CommentContent} "*"+ "/" +CommentContent = ( [^*] | \*+ [^/*] )* /* adjust syntax font-lock */ +Identifier = [:jletter:] [:jletterdigit:]* + +/* ________________________________________________________________ + A literal integer is is a number beginning with a number between + one and nine followed by zero or more numbers between + zero and nine or just a zero. + + A identifier integer is a word beginning a letter between A and Z, + a and z, or an underscore followed by zero or more letters between + A and Z, a and z, zero and nine, or an underscore. */ +dec_int_lit = 0 | [1-9][0-9]* +dec_int_id = [A-Za-z_][A-Za-z_0-9]* +DIGIT = [0-9] +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}*(["D"|"d"|"E"|"e"]([+|-]?){DIGIT}+)? +INT = [+|-]?{DIGIT}+ +BOOL = [T|F] +WORD = [A-Za-z]+ +WORDLIST = ["("]? [1A-Za-z]+ (","[A-Za-z]+)* [")"]? +GRAB = [^(" "|\r|\n|\r\n| \t\f)]+ +TOEOL = ~(\r|\n|\r\n) + + + +%% + + +<GETN>{ + /* get number of electrons */ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(GETCOMMA); + } +} + +<GETCOMMA>{ + "," {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(GETM); + } +} + +<GETM>{ + /* get number of orbitals */ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<YYINITIAL>{ + "CASSCF(" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(GETN); + } + "CAS(" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(GETN); + } + "Guess=Alter" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Guess=Only" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Guess=Read,Alter" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Pop=Regular=" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Pop=Full" {if (Settings.DEBUG) System.out.println(yytext()); + } + "SCF=Conven" {if (Settings.DEBUG) System.out.println(yytext()); + } + "MP2" {if (Settings.DEBUG) System.out.println(yytext()); + } + "NRoot=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "StateAverage" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Opt=Conical" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Spin" {if (Settings.DEBUG) System.out.println(yytext()); + } + "OrbLocal" {if (Settings.DEBUG) System.out.println(yytext()); + } + "OrbLocal=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "DavidsonDiag" {if (Settings.DEBUG) System.out.println(yytext()); + } + "FullDiag" {if (Settings.DEBUG) System.out.println(yytext()); + } + "NoFullDiag" {if (Settings.DEBUG) System.out.println(yytext()); + } + "StateGuess=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "StateGuess=Read" {if (Settings.DEBUG) System.out.println(yytext()); + } + "OrbRoot" {if (Settings.DEBUG) System.out.println(yytext()); + } + "SlaterDet" {if (Settings.DEBUG) System.out.println(yytext()); + } + "HWDet" {if (Settings.DEBUG) System.out.println(yytext()); + } + "RFO" {if (Settings.DEBUG) System.out.println(yytext()); + } + "QC" {if (Settings.DEBUG) System.out.println(yytext()); + } + "UNO" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Guess=Read" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Pop=NaturalOrbital" {if (Settings.DEBUG) System.out.println(yytext()); + } + "NPairs=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "Restart" {if (Settings.DEBUG) System.out.println(yytext()); + } + "DoOff" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Thresh=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "MP2States=" {if (Settings.DEBUG) System.out.println(yytext()); + } + "NFC=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "NFV=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "UseL906" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Polar=Numer" {if (Settings.DEBUG) System.out.println(yytext()); + } + "ITN" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITN); + } + "E2=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FLOATVAL); + } + "EUMP2=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FLOATVAL); + } + "QC" {if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +<ITN>{ + "=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITNFLOAT); + } + "MaxIt=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITNFLOAT); + } + "E=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITNFLOAT); + } + "DE=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITNFLOAT); + } + "Acc=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITNFLOAT); + } + "MCSCF converged." {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<ITNFLOAT>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITN); + } +} + +<FLOATVAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<INTVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} + http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/cbsQ.cup ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/cbsQ.cup b/datacat/cup_flex/cbsQ.cup new file mode 100644 index 0000000..4ff460a --- /dev/null +++ b/datacat/cup_flex/cbsQ.cup @@ -0,0 +1,166 @@ +import java_cup.runtime.*; +import javax.swing.*; +import java.util.*; +import java.io.*; + + + +/* +OUTPUT FORMAT:____________________________________________________________ +1NSERCH= 0 + more text + SCF Done: E(RHF) = -7.85284496695 A.U. after 8 cycles + more text + Maximum Force 0.000000 0.000450 YES + RMS Force 0.000000 0.000300 YES + more text +TO MONITOR:____________________________________________________________ + iteration, energy + +MANUALLY ADD TO CUP-GENERATED CLASS IN SCFaParser.java:________________ + + +//add to CUP$SCFaParser$actions +public ParseSCF2 parseSCF; + +//add to the constructor of CUP$SCFaParser$actions + parseSCF = new ParseSCF2(); + +*/ + +action code {: + //__________________________________ + public static boolean DEBUG = true; + private static JTable table; + private static final String tableLabel = "SCF Intermediate Results:"; +// private static String cycle = "0"; + + + public static JTable getTable() { + return table; + } + + public static String getTableLabel() { + return tableLabel; + } + +// } +:} + + + + +terminal FOUNDITER1, SCFDONE1, NSearch1, Energ1, MaxGrad1, RmsGrad1; +terminal MPStart, NMP, MPEnerg, MPMax, MPRms, MPDONE; +terminal Integer ITERATION1, MPITER; +terminal Float ENERGY1, MGRAD1, RGRAD1, MPENERGY, MPMGRAD, MPRGRAD; +non terminal startpt, scfintro, scfpat, scfcycle, cycle, grad1, grad2; +non terminal mp2, mpintro, mppat, mpcycle, mpcycle1, force1, force2; + + + +/* ___________ + The grammer */ + +startpt ::= scfintro + scfpat + SCFDONE1 + mp2 + MPDONE + {: if (DEBUG) System.out.println("CUP:gopt: end of parse tree "); + :} + ; + + + + +scfintro ::= + FOUNDITER1 + {: if (DEBUG) System.out.println("CUP:gopt: found the start of Iteration"); :} +; + +scfpat ::= scfpat scfcycle + {: if (DEBUG) System.out.println("CUP:gopt: in scfpat"); :} + | + scfcycle +// Originally: SCFDONE1 +; + +scfcycle ::= Energ1 ENERGY1:e +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: ENERGY "+e); + :} +cycle +; + + + + +cycle ::= NSearch1 ITERATION1:c +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: ITERATION "+c); + :} +grad1 +grad2 + ; + +grad1 ::= MaxGrad1 MGRAD1:mg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: Maximum Force "+mg); + :} +; + +grad2 ::= RmsGrad1 RGRAD1:rg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:gopt: RMS Force "+rg); + :} +; + +mp2 ::= mpintro mppat +{: + if (DEBUG) System.out.println("CUP:g1: in mp2 mpintro mppat"); + :} +; + +mpintro ::= +MPStart +{: + if (DEBUG) System.out.println("CUP:g1: MPSTart "); + :} +; + +mppat ::= mppat mpcycle1 +{: + if (DEBUG) System.out.println("CUP:g1: in mppat"); + :} +| +mpcycle1 +; + +mpcycle1 ::= MPEnerg MPENERGY:mpen +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: ENERGY "+mpen); + :} +mpcycle +; + + +mpcycle ::= NMP MPITER:it +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: MP ITERATION "+it); + :} +force1 +force2 +; + +force1 ::= MPMax MPMGRAD:mpmg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: MP Maximum Force "+mpmg); + :} +; + +force2 ::= MPRms MPRGRAD:mprg +{: //___________________________________________________________________ + if (DEBUG) System.out.println("CUP:g1: MP RMS Force "+mprg); + :} +; http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/cbsQ.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/cbsQ.flex b/datacat/cup_flex/cbsQ.flex new file mode 100644 index 0000000..8914f8e --- /dev/null +++ b/datacat/cup_flex/cbsQ.flex @@ -0,0 +1,204 @@ +import java_cup.runtime.*; + +%% + +%class CBSQLexer +%public +%unicode +%cup +%cupdebug +%state ITER +%state ITER2 +%state ITER3 +%state INTVALUE +%state FLOATVALUE +%state FLOAT1 +%state FLOAT2 +%state MP2 +%state MPOPT +%state FLOATMP1 +%state FLOATMP2 +%state FLOATMP3 +%state IGNOREALL +%state INTMP +%standalone +%8bit + +/* ___________________________________________ + Copied verbatim into generated lexer class: +*/ +%{ + public static boolean DEBUG = false; +%} + +LineTerminator = \r|\n|\r\n +InputCharacter = [^\r\n] +WhiteSpace = {LineTerminator} | [ \t\f] +Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} +TraditionalComment = "/*" [^*] ~"*/" +EndOfLineComment = "//" {InputCharacter}* {LineTerminator} +DocumentationComment = "/**" {CommentContent} "*"+ "/" +CommentContent = ( [^*] | \*+ [^/*] )* /* adjust syntax font-coloring */ +Identifier = [:jletter:] [:jletterdigit:]* +dec_int_lit = 0 | [1-9][0-9]* +dec_int_id = [A-Za-z_][A-Za-z_0-9]* +DIGIT = [0-9] +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}+ +INT = [+|-]?{DIGIT}+ +BOOL = [T|F] +EQ = "=" +STRING = [A-Z]+ +GRAB = [^(" "|\r|\n|\r\n| \t\f)]+ + +%% + +<YYINITIAL>{ + "Number of steps in this run" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found Number of steps"); + yybegin(ITER); + return new Symbol(G1Sym.FOUNDITER1); + } +} + +<ITER>{ + "Step number" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found the Step number"); + yybegin(INTVALUE); + return new Symbol(G1Sym.NSearch1);} + + "SCF Done: E(RHF) =" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found the energy in ITER"); + yybegin(FLOATVALUE); + return new Symbol(G1Sym.Energ1);} + + "Maximum Force" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found Maximum Force"); + yybegin(FLOAT1); + return new Symbol(G1Sym.MaxGrad1);} + + "RMS Force" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found RMS Force"); + yybegin(FLOAT2); + return new Symbol(G1Sym.RmsGrad1);} + + + "Optimization completed" { +if (Settings.DEBUG) System.out.println("CBSQFlex: SCFDONE1, Optimization completed"); + yybegin(MP2); + return new Symbol(G1Sym.SCFDONE1);} + + .|\n {} + +} + + +<FLOATVALUE>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found the energy in FLOATVALUE"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITER); + return new Symbol(G1Sym.ENERGY1, new Float(yytext()));} +} + +<FLOAT1>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found the maximum force"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITER); + return new Symbol(G1Sym.MGRAD1, new Float(yytext()));} +} + +<FLOAT2>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found the RMS force"); +if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITER); + return new Symbol(G1Sym.RGRAD1, new Float(yytext()));} +} + +<INTVALUE>{ + {INT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found iteration"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin (ITER); + return new Symbol(G1Sym.ITERATION1, new Integer(yytext())); +} +} + +<MP2>{ + "MP2/6-31G(d') Opt=RCFC" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found MP2(Full)"); + yybegin(MPOPT); + return new Symbol(G1Sym.MPStart);} + } + + +<MPOPT>{ + + "Step number" { +if (Settings.DEBUG) System.out.println("CBSQFlex: Found the Step number for MP"); + yybegin(INTMP); + return new Symbol(G1Sym.NMP);} + + "EUMP2 = " { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found MP2 energy"); + yybegin(FLOATMP1); + return new Symbol(G1Sym.MPEnerg);} + + "Maximum Force" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found Maximum Force"); + yybegin(FLOATMP2); + return new Symbol(G1Sym.MPMax);} + + "RMS Force" { + if (Settings.DEBUG) System.out.println("CBSQFlex: Found RMS Force"); + yybegin(FLOATMP3); + return new Symbol(G1Sym.MPRms);} + + + "Optimization completed" { + yybegin(IGNOREALL); + return new Symbol(G1Sym.MPDONE);} + + + .|\n {} + } + + +<FLOATMP1>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: MP2 Found the energy"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(MPOPT); + return new Symbol(G1Sym.MPENERGY, new Float(yytext()));} +} + +<FLOATMP2>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: MP2 Found the maximum force"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin(MPOPT); + return new Symbol(G1Sym.MPMGRAD, new Float(yytext()));} +} + +<FLOATMP3>{ + {FLOAT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: MP2 Found the RMS force"); +if (Settings.DEBUG) System.out.println(yytext()); + yybegin(MPOPT); + return new Symbol(G1Sym.MPRGRAD, new Float(yytext()));} +} + +<INTMP>{ + {INT} { + if (Settings.DEBUG) System.out.println("CBSQFlex: MP2 Found iteration"); + if (Settings.DEBUG) System.out.println(yytext()); + yybegin (MPOPT); + return new Symbol(G1Sym.MPITER, new Integer(yytext()));} +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/ci.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/ci.flex b/datacat/cup_flex/ci.flex new file mode 100644 index 0000000..e5a9860 --- /dev/null +++ b/datacat/cup_flex/ci.flex @@ -0,0 +1,134 @@ +/* CID and CISD Keywords + Last Update: 6/26/2001 + http://www.gaussian.com/00000423.htm +*/ + + + +%% + + + +%class CI +%public +%unicode +/* +%cup +%cupdebug +*/ +%ignorecase + +%state FLOATVAL +%state INTVAL +%state IGNOREALL + +%standalone +%8bit +%{ + public static boolean DEBUG = false; +%} + +/* ______ + Macros */ +LineTerminator = \r|\n|\r\n +InputCharacter = [^\r\n] +WhiteSpace = {LineTerminator} | [ \t\f] + +/* ________ + Comments */ +Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} +TraditionalComment = "/*" [^*] ~"*/" +EndOfLineComment = "//" {InputCharacter}* {LineTerminator} +DocumentationComment = "/**" {CommentContent} "*"+ "/" +CommentContent = ( [^*] | \*+ [^/*] )* /* adjust syntax font-lock */ +Identifier = [:jletter:] [:jletterdigit:]* + +/* ________________________________________________________________ + A literal integer is is a number beginning with a number between + one and nine followed by zero or more numbers between + zero and nine or just a zero. + + A identifier integer is a word beginning a letter between A and Z, + a and z, or an underscore followed by zero or more letters between + A and Z, a and z, zero and nine, or an underscore. */ +dec_int_lit = 0 | [1-9][0-9]* +dec_int_id = [A-Za-z_][A-Za-z_0-9]* +DIGIT = [0-9] +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}*(["D"|"d"|"E"|"e"]([+|-]?){DIGIT}+)? +INT = [+|-]?{DIGIT}+ +BOOL = [T|F] +WORD = [A-Za-z]+ +WORDLIST = ["("]? [1A-Za-z]+ (","[A-Za-z]+)* [")"]? +GRAB = [^(" "|\r|\n|\r\n| \t\f)]+ +TOEOL = ~(\r|\n|\r\n) + + + +%% + + + +/* ___________ + Description */ + +<YYINITIAL>{ + "CID" {if (Settings.DEBUG) System.out.println(yytext()); + } + "CISD" {if (Settings.DEBUG) System.out.println(yytext()); + } + "CI" {if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +/* _______ + Options */ + +<YYINITIAL>{ + "FC" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Full" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Conver=" {yybegin(INTVAL); + if (Settings.DEBUG) System.out.println(yytext()); + } + "MaxCyc=" {yybegin(INTVAL); + if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +/* __________________ + Examples, Energies */ + +<YYINITIAL>{ + "DE(CI)=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FLOATVAL); + } + "E(CI)=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FLOATVAL); + } + "NORM(A)=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FLOATVAL); + } + .|\n {} +} + +<FLOATVAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<INTVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} + http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/cis.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/cis.flex b/datacat/cup_flex/cis.flex new file mode 100644 index 0000000..265874e --- /dev/null +++ b/datacat/cup_flex/cis.flex @@ -0,0 +1,328 @@ +/* CIS Keyword + Last Update: 6/26/2001 + http://www.gaussian.com/00000426.htm +*/ + + + +%% + + + +%class CIS +%public +%unicode +/* +%cup +%cupdebug +*/ +%ignorecase + +%state ITERATIONVAL +%state DIMENSIONVAL +%state ROOTVAL +%state AFTERROOT +%state DELTAVAL +%state ROOTEV +%state CHANGEIS +%state CHANGEVAL +%state EXCITATION +%state EXCITEDSTATE +%state SYMMETRY +%state EXCITENERGY +%state EV +%state FREQ +%state NM +%state FVAL +%state STRENGTH +%state TRANSITION +%state CISENERGY +%state FLOATVAL +%state INTVAL +%state IGNOREALL + +%standalone +%8bit +%{ + public static boolean DEBUG = false; +%} + +/* ______ + Macros */ +LineTerminator = \r|\n|\r\n +InputCharacter = [^\r\n] +WhiteSpace = {LineTerminator} | [ \t\f] + +/* ________ + Comments */ +Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} +TraditionalComment = "/*" [^*] ~"*/" +EndOfLineComment = "//" {InputCharacter}* {LineTerminator} +DocumentationComment = "/**" {CommentContent} "*"+ "/" +CommentContent = ( [^*] | \*+ [^/*] )* /* adjust syntax font-lock */ +Identifier = [:jletter:] [:jletterdigit:]* + +/* ________________________________________________________________ + A literal integer is is a number beginning with a number between + one and nine followed by zero or more numbers between + zero and nine or just a zero. + + A identifier integer is a word beginning a letter between A and Z, + a and z, or an underscore followed by zero or more letters between + A and Z, a and z, zero and nine, or an underscore. */ +dec_int_lit = 0 | [1-9][0-9]* +dec_int_id = [A-Za-z_][A-Za-z_0-9]* +DIGIT = [0-9] +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}*(["D"|"d"|"E"|"e"]([+|-]?){DIGIT}+)? +INT = [+|-]?{DIGIT}+ +BOOL = [T|F] +WORD = [A-Za-z]+ +WORDLIST = ["("]? [1A-Za-z]+ (","[A-Za-z]+)* [")"]? +GRAB = [^(" "|\r|\n|\r\n| \t\f)]+ +TOEOL = ~(\r|\n|\r\n) + + + +%% + + + +/* ____________________________________ + Description, state selection options */ + +<YYINITIAL>{ + "Density" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Singlets" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Triplets" {if (Settings.DEBUG) System.out.println(yytext()); + } + "50-50" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Root=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "NStates=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "Add=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "Densities" {if (Settings.DEBUG) System.out.println(yytext()); + } + "TransitionDensities" {if (Settings.DEBUG) System.out.println(yytext()); + } + "AllTransitionDensities" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Direct" {if (Settings.DEBUG) System.out.println(yytext()); + } + "MO" {if (Settings.DEBUG) System.out.println(yytext()); + } + "AO" {if (Settings.DEBUG) System.out.println(yytext()); + } + "FC" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Conver=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "Read" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Restart" {if (Settings.DEBUG) System.out.println(yytext()); + } + "RWFRestart" {if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +/* _________________ + Debugging options */ +<YYINITIAL>{ + "ICDiag" {if (Settings.DEBUG) System.out.println(yytext()); + } + "MaxDiag=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "MaxDavidson" {if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +/* __________________ + Examples, Energies */ + +<YYINITIAL>{ + "DE(CI)=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FLOATVAL); + } + "Iteration" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ITERATIONVAL); + } + "Dimension" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(DIMENSIONVAL); + } + "Root" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ROOTVAL); + } + "Excitation Energies [eV] at current iteration:" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Excited States From <AA,BB:AA,BB> singles matrix:" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Excitation energies and oscillator strengths:" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(EXCITATION); + } + .|\n {} +} + +<ITERATIONVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<DIMENSIONVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + + + +/* ROOTVAL and related states */ + +<ROOTVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(AFTERROOT); + } +} + +<AFTERROOT>{ + "not converged, maximum delta is" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(DELTAVAL); + } + ":" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(ROOTEV); + } +} + +<DELTAVAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<ROOTEV>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(CHANGEIS); + } +} + +<CHANGEIS>{ + "Change is" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(CHANGEVAL); + } +} + +<CHANGEVAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + + + + + +/* EXCITATION and related states */ + +<EXCITATION>{ + "Excited State" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(EXCITEDSTATE); + } +} + +<EXCITEDSTATE>{ + {INT}":" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(SYMMETRY); + } +} + +<SYMMETRY>{ + {WORD} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(EXCITENERGY); + } +} + +<EXCITENERGY>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(EV); + } +} + +<EV>{ + "eV" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FREQ); + } +} + +<FREQ>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(NM); + } +} + +<NM>{ + "nm" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(FVAL); + } +} + +<FVAL>{ + "f=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(STRENGTH); + } +} + +<STRENGTH>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(TRANSITION); + } +} + +<TRANSITION>{ + {INT}"->"{INT} {if (Settings.DEBUG) System.out.println(yytext()); + } + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + } + "Total Energy, E(Cis) =" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(CISENERGY); + } +} + +<CISENERGY>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(IGNOREALL); + } +} + + + + + +<FLOATVAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<INTVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} + http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/conf.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/conf.flex b/datacat/cup_flex/conf.flex new file mode 100644 index 0000000..1a4f430 --- /dev/null +++ b/datacat/cup_flex/conf.flex @@ -0,0 +1,66 @@ +package GridChem; +import java.util.*; +import GridChem.*; +import GridChem.util.Settings; + +%% + + + +%class Conf +%public +%unicode +/* +%cup +%cupdebug +%ignorecase +*/ + +%state SEQ +%state DATAF +%state IGNOREALL + +%standalone +%8bit + +%{ + public static boolean DEBUG = false; + public static Set datafileList; +%} + +FNAME = [A-Za-z0-9_"."" ":\-\\\/]+ +DIGIT = [0-9] +INT = [+|-]?{DIGIT}+ +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}*(["D"|"d"|"E"|"e"]([+|-]?){DIGIT}+)? + + +%% + + + +<YYINITIAL>{ + "qcrjm2002" {if (Settings.DEBUG) System.out.println(yytext()); + Conf.datafileList = new TreeSet(); + } + "datafile" {yybegin(SEQ);} +} + +<SEQ>{ + "=" {yybegin(DATAF);} +} + +<DATAF>{ + {FNAME} {Conf.datafileList.add(yytext()); + for(Iterator myi = Conf.datafileList.iterator(); myi.hasNext();) + if (Settings.DEBUG) System.out.println(myi.next()); + if (Settings.DEBUG) System.out.println("----------"); + yybegin(YYINITIAL); + } +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} + http://git-wip-us.apache.org/repos/asf/airavata-sandbox/blob/4231ac35/datacat/cup_flex/dft.flex ---------------------------------------------------------------------- diff --git a/datacat/cup_flex/dft.flex b/datacat/cup_flex/dft.flex new file mode 100644 index 0000000..5afa5d7 --- /dev/null +++ b/datacat/cup_flex/dft.flex @@ -0,0 +1,229 @@ +/* Density Functional Methods (DFT) Keywords + Last Update: 6/26/2001 + http://www.gaussian.com/00000432.htm +*/ + + + +%% + + + +%class DFT +%public +%unicode +/* +%cup +%cupdebug +*/ +%ignorecase + +%state FLOATVAL +%state INTVAL +%state MMMM +%state NNNN +%state AU +%state IGNOREALL + +%standalone +%8bit +%{ + public static boolean DEBUG = false; +%} + +/* ______ + Macros */ +LineTerminator = \r|\n|\r\n +InputCharacter = [^\r\n] +WhiteSpace = {LineTerminator} | [ \t\f] + +/* ________ + Comments */ +Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} +TraditionalComment = "/*" [^*] ~"*/" +EndOfLineComment = "//" {InputCharacter}* {LineTerminator} +DocumentationComment = "/**" {CommentContent} "*"+ "/" +CommentContent = ( [^*] | \*+ [^/*] )* /* adjust syntax font-lock */ +Identifier = [:jletter:] [:jletterdigit:]* + +/* ________________________________________________________________ + A literal integer is is a number beginning with a number between + one and nine followed by zero or more numbers between + zero and nine or just a zero. + + A identifier integer is a word beginning a letter between A and Z, + a and z, or an underscore followed by zero or more letters between + A and Z, a and z, zero and nine, or an underscore. */ +dec_int_lit = 0 | [1-9][0-9]* +dec_int_id = [A-Za-z_][A-Za-z_0-9]* +DIGIT = [0-9] +FLOAT = [+|-]?{DIGIT}+"."{DIGIT}*(["D"|"d"|"E"|"e"]([+|-]?){DIGIT}+)? +INT = [+|-]?{DIGIT}+ +BOOL = [T|F] +WORD = [A-Za-z]+ +WORDLIST = ["("]? [1A-Za-z]+ (","[A-Za-z]+)* [")"]? +GRAB = [^(" "|\r|\n|\r\n| \t\f)]+ +TOEOL = ~(\r|\n|\r\n) + + + +%% + + + +/* ____________________ + Exchange Functionals */ + +<YYINITIAL>{ + "HFS" {if (Settings.DEBUG) System.out.println(yytext()); + } + "XAlpha" {if (Settings.DEBUG) System.out.println(yytext()); + } + "HFB" {if (Settings.DEBUG) System.out.println(yytext()); + } +} + +/* ______________________________________________ + Exchange Functionals Combined with Correlation */ + +<YYINITIAL>{ + "PW91" {if (Settings.DEBUG) System.out.println(yytext()); + } + "S" {if (Settings.DEBUG) System.out.println(yytext()); + } + "XA" {if (Settings.DEBUG) System.out.println(yytext()); + } + "B" {if (Settings.DEBUG) System.out.println(yytext()); + } + "MPW" {if (Settings.DEBUG) System.out.println(yytext()); + } + "G96" {if (Settings.DEBUG) System.out.println(yytext()); + } +} + +/* ___________________________________________________________ + Correlation Functionals: must be combined with an exchange */ + +<YYINITIAL>{ + "VWN" {if (Settings.DEBUG) System.out.println(yytext()); + } + "LSDA" {if (Settings.DEBUG) System.out.println(yytext()); + } + "VWN5" {if (Settings.DEBUG) System.out.println(yytext()); + } + "LYP" {if (Settings.DEBUG) System.out.println(yytext()); + } + "PL" {if (Settings.DEBUG) System.out.println(yytext()); + } + "P86" {if (Settings.DEBUG) System.out.println(yytext()); + } + "PW91" {if (Settings.DEBUG) System.out.println(yytext()); + } + "B96" {if (Settings.DEBUG) System.out.println(yytext()); + } +} + +/* __________________ + Hybrid Functionals */ + +<YYINITIAL>{ + "B3LYP" {if (Settings.DEBUG) System.out.println(yytext()); + } + "B3P86" {if (Settings.DEBUG) System.out.println(yytext()); + } + "B3PW91" {if (Settings.DEBUG) System.out.println(yytext()); + } + "B1B96" {if (Settings.DEBUG) System.out.println(yytext()); + } + "B1LHYP" {if (Settings.DEBUG) System.out.println(yytext()); + } + "MPW1PW91" {if (Settings.DEBUG) System.out.println(yytext()); + } + "G961LYP" {if (Settings.DEBUG) System.out.println(yytext()); + } + "BHandH" {if (Settings.DEBUG) System.out.println(yytext()); + } + "BHandHLYP" {if (Settings.DEBUG) System.out.println(yytext()); + } +} + +/* ____________________________________________________________ + User-defined, local exchange, non-local exchange corrections */ + +<YYINITIAL>{ + "IOp(5/45=" {yybegin(MMMM); + if (Settings.DEBUG) System.out.println(yytext()); + } + "IOp(5/46=" {yybegin(MMMM); + if (Settings.DEBUG) System.out.println(yytext()); + } + "IOp(5/47=" {yybegin(MMMM); + if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +<MMMM>{ + {INT} {yybegin(NNNN); + if (Settings.DEBUG) System.out.println(yytext()); + } +} + +<NNNN>{ + {INT} {yybegin(YYINITIAL); + if (Settings.DEBUG) System.out.println(yytext()); + } +} + +/* __________________________________________________ + Accuracy considerations; convergence and stability */ + +<YYINITIAL>{ + "Int=FineGrid" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Int(Grid=" {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(INTVAL); + } + "SCF=Tight" {if (Settings.DEBUG) System.out.println(yytext()); + } + "SCF=VShift" {if (Settings.DEBUG) System.out.println(yytext()); + } + "SCF=QC" {if (Settings.DEBUG) System.out.println(yytext()); + } + "Stable=Opt" {if (Settings.DEBUG) System.out.println(yytext()); + } + .|\n {} +} + +/* ________________ + Examples, energy */ + +<YYINITIAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(AU); + } +} + +<AU>{ + "A.U. after" {if (Settings.DEBUG) System.out.println(yytext()); + } +} + +<FLOATVAL>{ + {FLOAT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<INTVAL>{ + {INT} {if (Settings.DEBUG) System.out.println(yytext()); + yybegin(YYINITIAL); + } +} + +<IGNOREALL>{ + .|\n {} +} + +.|\n {} +
