git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1559 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2008-03-01 00:06:37 +00:00
parent 9346bcd722
commit 6700000007
39 changed files with 8783 additions and 8783 deletions

View File

@ -1,73 +1,73 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: PoemsChain.h * * FILE NAME: PoemsChain.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef POEMSCHAIN_H_ #ifndef POEMSCHAIN_H_
#define POEMSCHAIN_H_ #define POEMSCHAIN_H_
#include "poemslist.h" #include "poemslist.h"
struct ChildRingData { struct ChildRingData {
List<int> * childRing; List<int> * childRing;
int entranceNodeId; int entranceNodeId;
}; };
struct POEMSChain{ struct POEMSChain{
~POEMSChain(){ ~POEMSChain(){
for(int i = 0; i < childChains.GetNumElements(); i++) for(int i = 0; i < childChains.GetNumElements(); i++)
{ {
delete childChains(i); delete childChains(i);
} }
} }
//void printTreeStructure(int tabs); //void printTreeStructure(int tabs);
//void getTreeAsList(List<int> * temp); //void getTreeAsList(List<int> * temp);
List<int> listOfNodes; List<int> listOfNodes;
List<POEMSChain> childChains; List<POEMSChain> childChains;
POEMSChain * parentChain; POEMSChain * parentChain;
List<ChildRingData> childRings; List<ChildRingData> childRings;
void printTreeStructure(int tabs){ void printTreeStructure(int tabs){
for(int i = 0; i < tabs; i++) for(int i = 0; i < tabs; i++)
{ {
cout << "\t"; cout << "\t";
} }
cout << "Chain: "; cout << "Chain: ";
for(int i = 0; i < listOfNodes.GetNumElements(); i++) for(int i = 0; i < listOfNodes.GetNumElements(); i++)
{ {
cout << *(listOfNodes(i)) << " "; cout << *(listOfNodes(i)) << " ";
} }
cout << endl; cout << endl;
for(int i = 0; i < childChains.GetNumElements(); i++) for(int i = 0; i < childChains.GetNumElements(); i++)
{ {
childChains(i)->printTreeStructure(tabs + 1); childChains(i)->printTreeStructure(tabs + 1);
} }
} }
void getTreeAsList(List<int> * temp) void getTreeAsList(List<int> * temp)
{ {
for(int i = 0; i < listOfNodes.GetNumElements(); i++) for(int i = 0; i < listOfNodes.GetNumElements(); i++)
{ {
int * integer = new int; int * integer = new int;
*integer = *(listOfNodes(i)); *integer = *(listOfNodes(i));
temp->Append(integer); temp->Append(integer);
} }
for(int i = 0; i < childChains.GetNumElements(); i++) for(int i = 0; i < childChains.GetNumElements(); i++)
{ {
childChains(i)->getTreeAsList(temp); childChains(i)->getTreeAsList(temp);
} }
} }
}; };
#endif #endif

View File

@ -1,283 +1,283 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: SystemProcessor.h * * FILE NAME: SystemProcessor.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef _SYS_PROCESSOR_H_ #ifndef _SYS_PROCESSOR_H_
#define _SYS_PROCESSOR_H_ #define _SYS_PROCESSOR_H_
#include "poemslist.h" #include "poemslist.h"
#include "poemstree.h" #include "poemstree.h"
#include "POEMSChain.h" #include "POEMSChain.h"
struct POEMSNode { struct POEMSNode {
List<POEMSNode> links; List<POEMSNode> links;
List<bool> taken; List<bool> taken;
int idNumber; int idNumber;
bool visited; bool visited;
~POEMSNode(){ ~POEMSNode(){
for(int i = 0; i < taken.GetNumElements(); i++) for(int i = 0; i < taken.GetNumElements(); i++)
{ {
delete taken(i); delete taken(i);
} }
}; };
}; };
class SystemProcessor{ class SystemProcessor{
private: private:
Tree nodes; Tree nodes;
// List<POEMSNode> forDeletion; // List<POEMSNode> forDeletion;
List<POEMSChain> headsOfSystems; List<POEMSChain> headsOfSystems;
List<List<int> > ringsInSystem; List<List<int> > ringsInSystem;
POEMSNode * findSingleLink(TreeNode * aNode); POEMSNode * findSingleLink(TreeNode * aNode);
POEMSChain * AddNewChain(POEMSNode * currentNode); POEMSChain * AddNewChain(POEMSNode * currentNode);
bool setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNode); bool setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNode);
public: public:
SystemProcessor(void); SystemProcessor(void);
~SystemProcessor(void) { ~SystemProcessor(void) {
headsOfSystems.DeleteValues(); headsOfSystems.DeleteValues();
for(int i = 0; i < ringsInSystem.GetNumElements(); i++) for(int i = 0; i < ringsInSystem.GetNumElements(); i++)
{ {
for(int k = 0; k < ringsInSystem(i)->GetNumElements(); i++) for(int k = 0; k < ringsInSystem(i)->GetNumElements(); i++)
{ {
delete (*ringsInSystem(i))(k); delete (*ringsInSystem(i))(k);
} }
} }
}; };
void processArray(int** links, int numLinks); void processArray(int** links, int numLinks);
List<POEMSChain> * getSystemData(); List<POEMSChain> * getSystemData();
int getNumberOfHeadChains(); int getNumberOfHeadChains();
}; };
SystemProcessor::SystemProcessor(void){ SystemProcessor::SystemProcessor(void){
} }
void SystemProcessor::processArray(int** links, int numLinks) void SystemProcessor::processArray(int** links, int numLinks)
{ {
bool * false_var; //holds the value false; needed because a constant cannot be put into a list; the list requires a bool * false_var; //holds the value false; needed because a constant cannot be put into a list; the list requires a
//reference. //reference.
for(int i = 0; i < numLinks; i++) //go through all the links in the input array for(int i = 0; i < numLinks; i++) //go through all the links in the input array
{ {
if(!nodes.Find(links[i][0])) //if the first node in the pair is not found in the storage tree if(!nodes.Find(links[i][0])) //if the first node in the pair is not found in the storage tree
{ {
POEMSNode * newNode = new POEMSNode; //make a new node POEMSNode * newNode = new POEMSNode; //make a new node
// forDeletion.Append(newNode); // forDeletion.Append(newNode);
newNode->idNumber = links[i][0]; //set its ID to the value newNode->idNumber = links[i][0]; //set its ID to the value
newNode->visited = false; //set it to be unvisited newNode->visited = false; //set it to be unvisited
nodes.Insert(links[i][0], links[i][0], (void *) newNode); //and add it to the tree storage structure nodes.Insert(links[i][0], links[i][0], (void *) newNode); //and add it to the tree storage structure
} }
if(!nodes.Find(links[i][1])) //repeat process for the other half of each link if(!nodes.Find(links[i][1])) //repeat process for the other half of each link
{ {
POEMSNode * newNode = new POEMSNode; POEMSNode * newNode = new POEMSNode;
// forDeletion.Append(newNode); // forDeletion.Append(newNode);
newNode->idNumber = links[i][1]; newNode->idNumber = links[i][1];
newNode->visited = false; newNode->visited = false;
nodes.Insert(links[i][1], links[i][1], (void *) newNode); nodes.Insert(links[i][1], links[i][1], (void *) newNode);
} }
POEMSNode * firstNode = (POEMSNode *)nodes.Find(links[i][0]); //now that we are sure both nodes exist, POEMSNode * firstNode = (POEMSNode *)nodes.Find(links[i][0]); //now that we are sure both nodes exist,
POEMSNode * secondNode = (POEMSNode *)nodes.Find(links[i][1]); //we can get both of them out of the tree POEMSNode * secondNode = (POEMSNode *)nodes.Find(links[i][1]); //we can get both of them out of the tree
firstNode->links.Append(secondNode); //and add the link from the first to the second... firstNode->links.Append(secondNode); //and add the link from the first to the second...
false_var = new bool; false_var = new bool;
*false_var = false; //make a new false boolean to note that the link between these two *false_var = false; //make a new false boolean to note that the link between these two
firstNode->taken.Append(false_var); //has not already been taken, and append it to the taken list firstNode->taken.Append(false_var); //has not already been taken, and append it to the taken list
secondNode->links.Append(firstNode); //repeat process for link from second node to first secondNode->links.Append(firstNode); //repeat process for link from second node to first
false_var = new bool; false_var = new bool;
*false_var = false; *false_var = false;
secondNode->taken.Append(false_var); secondNode->taken.Append(false_var);
} }
TreeNode * temp = nodes.GetRoot(); //get the root node of the node storage tree TreeNode * temp = nodes.GetRoot(); //get the root node of the node storage tree
POEMSNode * currentNode; POEMSNode * currentNode;
do do
{ {
currentNode = findSingleLink(temp); //find the start of the next available chain currentNode = findSingleLink(temp); //find the start of the next available chain
if(currentNode != NULL) if(currentNode != NULL)
{ {
headsOfSystems.Append(AddNewChain(currentNode)); //and add it to the headsOfSystems list of chains headsOfSystems.Append(AddNewChain(currentNode)); //and add it to the headsOfSystems list of chains
} }
} }
while(currentNode != NULL); //repeat this until all chains have been added while(currentNode != NULL); //repeat this until all chains have been added
} }
POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){ POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){
if(currentNode == NULL) //Termination condition; if the currentNode is null, then return null if(currentNode == NULL) //Termination condition; if the currentNode is null, then return null
{ {
return NULL; return NULL;
} }
int * tmp; int * tmp;
POEMSNode * nextNode = NULL; //nextNode stores the proposed next node to add to the chain. this will be checked to make sure no backtracking is occuring before being assigned as the current node. POEMSNode * nextNode = NULL; //nextNode stores the proposed next node to add to the chain. this will be checked to make sure no backtracking is occuring before being assigned as the current node.
POEMSChain * newChain = new POEMSChain; //make a new POEMSChain object. This will be the object returned POEMSChain * newChain = new POEMSChain; //make a new POEMSChain object. This will be the object returned
if(currentNode->links.GetNumElements() == 0) //if we have no links from this node, then the whole chain is only one node. Add this node to the chain and return it; mark node as visited for future reference if(currentNode->links.GetNumElements() == 0) //if we have no links from this node, then the whole chain is only one node. Add this node to the chain and return it; mark node as visited for future reference
{ {
currentNode->visited = true; currentNode->visited = true;
tmp = new int; tmp = new int;
*tmp = currentNode->idNumber; *tmp = currentNode->idNumber;
newChain->listOfNodes.Append(tmp); newChain->listOfNodes.Append(tmp);
return newChain; return newChain;
} }
while(currentNode->links.GetNumElements() <= 2) //we go until we get to a node that branches, or both branches have already been taken both branches can already be taken if a loop with no spurs is found in the input data while(currentNode->links.GetNumElements() <= 2) //we go until we get to a node that branches, or both branches have already been taken both branches can already be taken if a loop with no spurs is found in the input data
{ {
currentNode->visited = true; currentNode->visited = true;
tmp = new int; tmp = new int;
*tmp = currentNode->idNumber; *tmp = currentNode->idNumber;
newChain->listOfNodes.Append(tmp); //append the current node to the chain & mark as visited newChain->listOfNodes.Append(tmp); //append the current node to the chain & mark as visited
//cout << "Appending node " << currentNode->idNumber << " to chain" << endl; //cout << "Appending node " << currentNode->idNumber << " to chain" << endl;
nextNode = currentNode->links.GetHeadElement()->value; //the next node is the first or second value stored in the links array nextNode = currentNode->links.GetHeadElement()->value; //the next node is the first or second value stored in the links array
//of the current node. We get the first value... //of the current node. We get the first value...
if(!setLinkVisited(currentNode, nextNode)) //...and see if it points back to where we came from. If it does... if(!setLinkVisited(currentNode, nextNode)) //...and see if it points back to where we came from. If it does...
{ //either way, we set this link as visited { //either way, we set this link as visited
if(currentNode->links.GetNumElements() == 1) //if it does, then if that is the only link to this node, we're done with the chain, so append the chain to the list and return the newly created chain if(currentNode->links.GetNumElements() == 1) //if it does, then if that is the only link to this node, we're done with the chain, so append the chain to the list and return the newly created chain
{ {
// headsOfSystems.Append(newChain); // headsOfSystems.Append(newChain);
return newChain; return newChain;
} }
nextNode = currentNode->links.GetHeadElement()->next->value;//follow the other link if there is one, so we go down the chain nextNode = currentNode->links.GetHeadElement()->next->value;//follow the other link if there is one, so we go down the chain
if(!setLinkVisited(currentNode, nextNode)) //mark link as followed, so we know not to backtrack if(!setLinkVisited(currentNode, nextNode)) //mark link as followed, so we know not to backtrack
{ {
// headsOfSystems.Append(newChain); // headsOfSystems.Append(newChain);
return newChain; //This condition, where no branches have occurred but both links have already return newChain; //This condition, where no branches have occurred but both links have already
//been taken can only occur in a loop with no spurs; add this loop to the //been taken can only occur in a loop with no spurs; add this loop to the
//system (currently added as a chain for consistency), and return. //system (currently added as a chain for consistency), and return.
} }
} }
currentNode = nextNode; //set the current node to be the next node in the chain currentNode = nextNode; //set the current node to be the next node in the chain
} }
currentNode->visited = true; currentNode->visited = true;
tmp = new int; tmp = new int;
*tmp = currentNode->idNumber; *tmp = currentNode->idNumber;
newChain->listOfNodes.Append(tmp); //append the last node before branch (node shared jointly with branch chains) newChain->listOfNodes.Append(tmp); //append the last node before branch (node shared jointly with branch chains)
//re-mark as visited, just to make sure //re-mark as visited, just to make sure
ListElement<POEMSNode> * tempNode = currentNode->links.GetHeadElement(); //go through all of the links, one at a time that branch ListElement<POEMSNode> * tempNode = currentNode->links.GetHeadElement(); //go through all of the links, one at a time that branch
POEMSChain * tempChain = NULL; //temporary variable to hold data POEMSChain * tempChain = NULL; //temporary variable to hold data
while(tempNode != NULL) //when we have followed all links, stop while(tempNode != NULL) //when we have followed all links, stop
{ {
if(setLinkVisited(tempNode->value, currentNode)) //dont backtrack, or create closed loops if(setLinkVisited(tempNode->value, currentNode)) //dont backtrack, or create closed loops
{ {
tempChain = AddNewChain(tempNode->value); //Add a new chain created out of the next node down that link tempChain = AddNewChain(tempNode->value); //Add a new chain created out of the next node down that link
tempChain->parentChain = newChain; //set the parent to be this chain tempChain->parentChain = newChain; //set the parent to be this chain
newChain->childChains.Append(tempChain); //append the chain to this chain's list of child chains newChain->childChains.Append(tempChain); //append the chain to this chain's list of child chains
} }
tempNode = tempNode->next; //go to process the next chain tempNode = tempNode->next; //go to process the next chain
} }
//headsOfSystems.Append(newChain); //append this chain to the system list //headsOfSystems.Append(newChain); //append this chain to the system list
return newChain; return newChain;
} }
POEMSNode * SystemProcessor::findSingleLink(TreeNode * aNode) POEMSNode * SystemProcessor::findSingleLink(TreeNode * aNode)
//This function takes the root of a search tree containing POEMSNodes and returns a POEMSNode corresponding to the start of a chain in the //This function takes the root of a search tree containing POEMSNodes and returns a POEMSNode corresponding to the start of a chain in the
//system. It finds a node that has not been visited before, and only has one link; this node will be used as the head of the chain. //system. It finds a node that has not been visited before, and only has one link; this node will be used as the head of the chain.
{ {
if(aNode == NULL) if(aNode == NULL)
{ {
return NULL; return NULL;
} }
POEMSNode * returnVal = (POEMSNode *)aNode->GetAuxData(); //get the poemsnode data out of the treenode POEMSNode * returnVal = (POEMSNode *)aNode->GetAuxData(); //get the poemsnode data out of the treenode
POEMSNode * detectLoneLoops = NULL; //is used to handle a loop that has no protruding chains POEMSNode * detectLoneLoops = NULL; //is used to handle a loop that has no protruding chains
if(returnVal->visited == false) if(returnVal->visited == false)
{ {
detectLoneLoops = returnVal; //if we find any node that has not been visited yet, save it detectLoneLoops = returnVal; //if we find any node that has not been visited yet, save it
} }
if(returnVal->links.GetNumElements() == 1 && returnVal->visited == false) //see if it has one element and hasnt been visited already if(returnVal->links.GetNumElements() == 1 && returnVal->visited == false) //see if it has one element and hasnt been visited already
{ {
return returnVal; //return the node is it meets this criteria return returnVal; //return the node is it meets this criteria
} }
returnVal = findSingleLink(aNode->Left()); //otherwise, check the left subtree returnVal = findSingleLink(aNode->Left()); //otherwise, check the left subtree
if(returnVal == NULL) //and if we find nothing... if(returnVal == NULL) //and if we find nothing...
{ {
returnVal = findSingleLink(aNode->Right()); //check the right subtree returnVal = findSingleLink(aNode->Right()); //check the right subtree
} }
if(returnVal == NULL) //if we could not find any chains if(returnVal == NULL) //if we could not find any chains
{ {
returnVal = detectLoneLoops; //see if we found any nodes at all that havent been processed returnVal = detectLoneLoops; //see if we found any nodes at all that havent been processed
} }
return returnVal; //return what we find (will be NULL if no new chains are return returnVal; //return what we find (will be NULL if no new chains are
//found) //found)
} }
bool SystemProcessor::setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNode) bool SystemProcessor::setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNode)
//setLinkVisited sets the links between these two nodes as visited. If they are already visited, it returns false. Otherwise, it sets //setLinkVisited sets the links between these two nodes as visited. If they are already visited, it returns false. Otherwise, it sets
//them as visited and returns true. This function is used to see whether a certain path has been taken already in the graph structure. //them as visited and returns true. This function is used to see whether a certain path has been taken already in the graph structure.
//If it has been, then we need to know so we dont follow it again; this prevents infinite recursion when there is a loop, and prevents //If it has been, then we need to know so we dont follow it again; this prevents infinite recursion when there is a loop, and prevents
//backtracking up a chain that has already been made. The list of booleans denoting if a link has been visited is called 'taken' and is //backtracking up a chain that has already been made. The list of booleans denoting if a link has been visited is called 'taken' and is
//part of the POEMSNode struct. The list is the same size as the list of pointers to other nodes, and stores the boolean visited/unvisited //part of the POEMSNode struct. The list is the same size as the list of pointers to other nodes, and stores the boolean visited/unvisited
//value for that particular link. Because each link is represented twice, (once at each node in the link), both of the boolean values need //value for that particular link. Because each link is represented twice, (once at each node in the link), both of the boolean values need
//to be set in the event that the link has to be set as visited. //to be set in the event that the link has to be set as visited.
{ {
//cout << "Checking link between nodes " << firstNode->idNumber << " and " << secondNode->idNumber << "... "; //cout << "Checking link between nodes " << firstNode->idNumber << " and " << secondNode->idNumber << "... ";
ListElement<POEMSNode> * tmp = firstNode->links.GetHeadElement(); //get the head element of the list of pointers for node 1 ListElement<POEMSNode> * tmp = firstNode->links.GetHeadElement(); //get the head element of the list of pointers for node 1
ListElement<bool> * tmp2 = firstNode->taken.GetHeadElement(); //get the head element of the list of bool isVisited flags for node 1 ListElement<bool> * tmp2 = firstNode->taken.GetHeadElement(); //get the head element of the list of bool isVisited flags for node 1
while(tmp->value != NULL || tmp2->value != NULL) //go through untill we reach the end of the lists while(tmp->value != NULL || tmp2->value != NULL) //go through untill we reach the end of the lists
{ {
if(tmp->value == secondNode) //if we find the link to the other node if(tmp->value == secondNode) //if we find the link to the other node
{ {
if(*(tmp2->value) == true) //if the link has already been visited if(*(tmp2->value) == true) //if the link has already been visited
{ {
//cout << "visited already" << endl; //cout << "visited already" << endl;
return false; //return false to indicate that the link has been visited before this attempt return false; //return false to indicate that the link has been visited before this attempt
} }
else //otherwise, visit it else //otherwise, visit it
{ {
*tmp2->value = true; *tmp2->value = true;
} }
break; break;
} }
tmp = tmp->next; //go check next link tmp = tmp->next; //go check next link
tmp2 = tmp2->next; tmp2 = tmp2->next;
} }
tmp = secondNode->links.GetHeadElement(); //now, if the link was unvisited, we need to go set the other node's list such that tmp = secondNode->links.GetHeadElement(); //now, if the link was unvisited, we need to go set the other node's list such that
//it also knows this link is being visited //it also knows this link is being visited
tmp2 = secondNode->taken.GetHeadElement(); tmp2 = secondNode->taken.GetHeadElement();
while(tmp->value != NULL || tmp2->value != NULL) //go through the list while(tmp->value != NULL || tmp2->value != NULL) //go through the list
{ {
if(tmp->value == firstNode) //if we find the link if(tmp->value == firstNode) //if we find the link
{ {
if(*(tmp2->value) == true) //and it has already been visited, then signal an error; this shouldnt ever happen if(*(tmp2->value) == true) //and it has already been visited, then signal an error; this shouldnt ever happen
{ {
cout << "Error in parsing structure! Should never reach this condition! \n" << cout << "Error in parsing structure! Should never reach this condition! \n" <<
"Record of visited links out of synch between two adjacent nodes.\n"; "Record of visited links out of synch between two adjacent nodes.\n";
return false; return false;
} }
else else
{ {
*tmp2->value = true; //set the appropriate value to true to indicate this link has been visited *tmp2->value = true; //set the appropriate value to true to indicate this link has been visited
} }
break; break;
} }
tmp = tmp->next; tmp = tmp->next;
tmp2 = tmp2->next; tmp2 = tmp2->next;
} }
//cout << "not visited" << endl; //cout << "not visited" << endl;
return true; //return true to indicate that this is the first time the link has been visited return true; //return true to indicate that this is the first time the link has been visited
} }
List<POEMSChain> * SystemProcessor::getSystemData(void) //Gets the list of POEMSChains that comprise the system. Might eventually only List<POEMSChain> * SystemProcessor::getSystemData(void) //Gets the list of POEMSChains that comprise the system. Might eventually only
//return chains linked to the reference plane, but currently returns every chain //return chains linked to the reference plane, but currently returns every chain
//in the system. //in the system.
{ {
return &headsOfSystems; return &headsOfSystems;
} }
int SystemProcessor::getNumberOfHeadChains(void) //This function isnt implemented yet, and might be taken out entirely; this was a holdover int SystemProcessor::getNumberOfHeadChains(void) //This function isnt implemented yet, and might be taken out entirely; this was a holdover
//from when I intended to return an array of chain pointers, rather than a list of chains //from when I intended to return an array of chain pointers, rather than a list of chains
//It will probably be deleted once I finish figuring out exactly what needs to be returned //It will probably be deleted once I finish figuring out exactly what needs to be returned
{ {
return 0; return 0;
} }
#endif #endif

View File

@ -1,27 +1,27 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: defines.h * * FILE NAME: defines.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef _DEFINES_H_ #ifndef _DEFINES_H_
#define _DEFINES_H_ #define _DEFINES_H_
enum SolverType { enum SolverType {
ONSOLVER = 0, ONSOLVER = 0,
PARTICLESOLVER = 1 PARTICLESOLVER = 1
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,163 +1,163 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: mat4x4.cpp * * FILE NAME: mat4x4.cpp *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#include "mat4x4.h" #include "mat4x4.h"
using namespace std; using namespace std;
Mat4x4::Mat4x4(){ Mat4x4::Mat4x4(){
numrows = numcols = 4; numrows = numcols = 4;
} }
Mat4x4::~Mat4x4(){ Mat4x4::~Mat4x4(){
} }
Mat4x4::Mat4x4(const Mat4x4& A){ Mat4x4::Mat4x4(const Mat4x4& A){
numrows = numcols = 4; numrows = numcols = 4;
elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2]; elements[0][3] = A.elements[0][3]; elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2]; elements[0][3] = A.elements[0][3];
elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2]; elements[1][3] = A.elements[1][3]; elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2]; elements[1][3] = A.elements[1][3];
elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2]; elements[2][3] = A.elements[2][3]; elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2]; elements[2][3] = A.elements[2][3];
elements[3][0] = A.elements[3][0];elements[3][1] = A.elements[3][1];elements[3][2] = A.elements[3][2]; elements[3][3] = A.elements[3][3]; elements[3][0] = A.elements[3][0];elements[3][1] = A.elements[3][1];elements[3][2] = A.elements[3][2]; elements[3][3] = A.elements[3][3];
} }
Mat4x4::Mat4x4(const VirtualMatrix& A){ Mat4x4::Mat4x4(const VirtualMatrix& A){
numrows = numcols = 4; numrows = numcols = 4;
// error check // error check
if( (A.GetNumRows() != 4) || (A.GetNumCols() != 4) ){ if( (A.GetNumRows() != 4) || (A.GetNumCols() != 4) ){
cerr << "illegal matrix size" << endl; cerr << "illegal matrix size" << endl;
exit(0); exit(0);
} }
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
for(int j=0;j<4;j++) for(int j=0;j<4;j++)
elements[i][j] = A.BasicGet(i,j); elements[i][j] = A.BasicGet(i,j);
} }
double& Mat4x4::operator_2int(int i, int j){ // array access double& Mat4x4::operator_2int(int i, int j){ // array access
return elements[i-1][j-1]; return elements[i-1][j-1];
} }
double Mat4x4::Get_2int(int i, int j) const{ double Mat4x4::Get_2int(int i, int j) const{
return elements[i-1][j-1]; return elements[i-1][j-1];
} }
void Mat4x4::Set_2int(int i, int j, double value){ void Mat4x4::Set_2int(int i, int j, double value){
elements[i-1][j-1] = value; elements[i-1][j-1] = value;
} }
double Mat4x4::BasicGet_2int(int i, int j) const{ double Mat4x4::BasicGet_2int(int i, int j) const{
return elements[i][j]; return elements[i][j];
} }
void Mat4x4::BasicSet_2int(int i, int j, double value){ void Mat4x4::BasicSet_2int(int i, int j, double value){
elements[i][j] = value; elements[i][j] = value;
} }
void Mat4x4::BasicIncrement_2int(int i, int j, double value){ void Mat4x4::BasicIncrement_2int(int i, int j, double value){
elements[i][j] += value; elements[i][j] += value;
} }
void Mat4x4::Const(double value){ void Mat4x4::Const(double value){
elements[0][0] = elements[0][1] = elements[0][2] = elements[0][3] = value; elements[0][0] = elements[0][1] = elements[0][2] = elements[0][3] = value;
elements[1][0] = elements[1][1] = elements[1][2] = elements[1][3] = value; elements[1][0] = elements[1][1] = elements[1][2] = elements[1][3] = value;
elements[2][0] = elements[2][1] = elements[2][2] = elements[2][3] = value; elements[2][0] = elements[2][1] = elements[2][2] = elements[2][3] = value;
elements[3][0] = elements[3][1] = elements[3][2] = elements[3][3] = value; elements[3][0] = elements[3][1] = elements[3][2] = elements[3][3] = value;
} }
MatrixType Mat4x4::GetType() const{ MatrixType Mat4x4::GetType() const{
return MAT4X4; return MAT4X4;
} }
istream& Mat4x4::ReadData(istream& c){ //input istream& Mat4x4::ReadData(istream& c){ //input
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
for(int j=0;j<4;j++) for(int j=0;j<4;j++)
c >> elements[i][j]; c >> elements[i][j];
return c; return c;
} }
ostream& Mat4x4::WriteData(ostream& c) const{ //output ostream& Mat4x4::WriteData(ostream& c) const{ //output
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
for(int j=0;j<4;j++) for(int j=0;j<4;j++)
c << elements[i][j] << ' '; c << elements[i][j] << ' ';
return c; return c;
} }
void Mat4x4::AssignVM(const VirtualMatrix& A){ void Mat4x4::AssignVM(const VirtualMatrix& A){
// error check // error check
if( (A.GetNumRows() != 4) || (A.GetNumCols() != 4) ){ if( (A.GetNumRows() != 4) || (A.GetNumCols() != 4) ){
cerr << "illegal matrix size" << endl; cerr << "illegal matrix size" << endl;
exit(0); exit(0);
} }
for(int i=0;i<numrows;i++) for(int i=0;i<numrows;i++)
for(int j=0;j<numcols;j++) for(int j=0;j<numcols;j++)
elements[i][j] = A.BasicGet(i,j); elements[i][j] = A.BasicGet(i,j);
} }
Mat4x4& Mat4x4::operator=(const Mat4x4& A){ // assignment operator Mat4x4& Mat4x4::operator=(const Mat4x4& A){ // assignment operator
elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2]; elements[0][3] = A.elements[0][3]; elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2]; elements[0][3] = A.elements[0][3];
elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2]; elements[1][3] = A.elements[1][3]; elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2]; elements[1][3] = A.elements[1][3];
elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2]; elements[2][3] = A.elements[2][3]; elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2]; elements[2][3] = A.elements[2][3];
elements[3][0] = A.elements[3][0];elements[3][1] = A.elements[3][1];elements[3][2] = A.elements[3][2]; elements[3][3] = A.elements[3][3]; elements[3][0] = A.elements[3][0];elements[3][1] = A.elements[3][1];elements[3][2] = A.elements[3][2]; elements[3][3] = A.elements[3][3];
return *this; return *this;
} }
Mat4x4& Mat4x4::operator=(const VirtualMatrix& A){ // overloaded = Mat4x4& Mat4x4::operator=(const VirtualMatrix& A){ // overloaded =
// error check // error check
if( (A.GetNumRows() != 4) || (A.GetNumCols() != 4) ){ if( (A.GetNumRows() != 4) || (A.GetNumCols() != 4) ){
cerr << "illegal matrix size" << endl; cerr << "illegal matrix size" << endl;
exit(0); exit(0);
} }
for(int i=0;i<numrows;i++) for(int i=0;i<numrows;i++)
for(int j=0;j<numcols;j++) for(int j=0;j<numcols;j++)
elements[i][j] = A.BasicGet(i,j); elements[i][j] = A.BasicGet(i,j);
return *this; return *this;
} }
Mat4x4& Mat4x4::operator*=(double b){ Mat4x4& Mat4x4::operator*=(double b){
elements[0][0] *= b; elements[0][1] *= b; elements[0][2] *= b; elements[0][3] *= b; elements[0][0] *= b; elements[0][1] *= b; elements[0][2] *= b; elements[0][3] *= b;
elements[1][0] *= b; elements[1][1] *= b; elements[1][2] *= b; elements[1][3] *= b; elements[1][0] *= b; elements[1][1] *= b; elements[1][2] *= b; elements[1][3] *= b;
elements[2][0] *= b; elements[2][1] *= b; elements[2][2] *= b; elements[2][3] *= b; elements[2][0] *= b; elements[2][1] *= b; elements[2][2] *= b; elements[2][3] *= b;
elements[3][0] *= b; elements[3][1] *= b; elements[3][2] *= b; elements[3][3] *= b; elements[3][0] *= b; elements[3][1] *= b; elements[3][2] *= b; elements[3][3] *= b;
return *this; return *this;
} }
Mat4x4& Mat4x4::Identity(){ Mat4x4& Mat4x4::Identity(){
elements[0][0] = 1.0; elements[0][0] = 1.0;
elements[0][1] = 0.0; elements[0][1] = 0.0;
elements[0][2] = 0.0; elements[0][2] = 0.0;
elements[0][3] = 0.0; elements[0][3] = 0.0;
elements[1][0] = 0.0; elements[1][0] = 0.0;
elements[1][1] = 1.0; elements[1][1] = 1.0;
elements[1][2] = 0.0; elements[1][2] = 0.0;
elements[1][3] = 0.0; elements[1][3] = 0.0;
elements[2][0] = 0.0; elements[2][0] = 0.0;
elements[2][1] = 0.0; elements[2][1] = 0.0;
elements[2][2] = 1.0; elements[2][2] = 1.0;
elements[2][3] = 0.0; elements[2][3] = 0.0;
elements[3][0] = 0.0; elements[3][0] = 0.0;
elements[3][1] = 0.0; elements[3][1] = 0.0;
elements[3][2] = 0.0; elements[3][2] = 0.0;
elements[3][3] = 1.0; elements[3][3] = 1.0;
return *this; return *this;
} }

View File

@ -1,68 +1,68 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: mat4x4.h * * FILE NAME: mat4x4.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef MAT4X4_H #ifndef MAT4X4_H
#define MAT4X4_H #define MAT4X4_H
#include "virtualmatrix.h" #include "virtualmatrix.h"
#include "matrix.h" #include "matrix.h"
class Vect4; class Vect4;
class Mat4x4 : public VirtualMatrix { class Mat4x4 : public VirtualMatrix {
double elements[4][4]; double elements[4][4];
public: public:
Mat4x4(); Mat4x4();
~Mat4x4(); ~Mat4x4();
Mat4x4(const Mat4x4& A); // copy constructor Mat4x4(const Mat4x4& A); // copy constructor
Mat4x4(const VirtualMatrix& A); // copy constructor Mat4x4(const VirtualMatrix& A); // copy constructor
double& operator_2int (int i, int j); // array access double& operator_2int (int i, int j); // array access
double Get_2int(int i, int j) const; double Get_2int(int i, int j) const;
void Set_2int(int i, int j, double value); void Set_2int(int i, int j, double value);
double BasicGet_2int(int i, int j) const; double BasicGet_2int(int i, int j) const;
void BasicSet_2int(int i, int j, double value); void BasicSet_2int(int i, int j, double value);
void BasicIncrement_2int(int i, int j, double value); void BasicIncrement_2int(int i, int j, double value);
void Const(double value); void Const(double value);
MatrixType GetType() const; MatrixType GetType() const;
std::istream& ReadData(std::istream& c); // input std::istream& ReadData(std::istream& c); // input
std::ostream& WriteData(std::ostream& c) const; // output std::ostream& WriteData(std::ostream& c) const; // output
void AssignVM(const VirtualMatrix& A); void AssignVM(const VirtualMatrix& A);
Mat4x4& operator=(const Mat4x4& A); // assignment operator Mat4x4& operator=(const Mat4x4& A); // assignment operator
Mat4x4& operator=(const VirtualMatrix& A); // overloaded = Mat4x4& operator=(const VirtualMatrix& A); // overloaded =
Mat4x4& operator*=(double b); Mat4x4& operator*=(double b);
Mat4x4& Identity(); Mat4x4& Identity();
friend Mat4x4 T(const Mat4x4& A); // a wasteful transpose friend Mat4x4 T(const Mat4x4& A); // a wasteful transpose
friend Mat4x4 CrossMat(Vect4& a); // a wasteful cross matrix implementation friend Mat4x4 CrossMat(Vect4& a); // a wasteful cross matrix implementation
friend void FastLU(Mat4x4& A, Mat4x4& LU, int *indx); friend void FastLU(Mat4x4& A, Mat4x4& LU, int *indx);
friend void FastLUSubs(Mat4x4& LU, Matrix& B, Matrix& C, int *indx); friend void FastLUSubs(Mat4x4& LU, Matrix& B, Matrix& C, int *indx);
friend void FastMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastTMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastTMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastNegMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastNegMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastNegTMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastNegTMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastMult(Mat4x4& A, Mat4x4& B, Mat4x4& C); friend void FastMult(Mat4x4& A, Mat4x4& B, Mat4x4& C);
friend void FastMultT(Mat4x4& A, Mat4x4& B, Mat4x4& C); friend void FastMultT(Mat4x4& A, Mat4x4& B, Mat4x4& C);
friend void FastAssignT(Mat4x4& A, Mat4x4& C); friend void FastAssignT(Mat4x4& A, Mat4x4& C);
}; };
#endif #endif

View File

@ -1,42 +1,42 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: matrices.h * * FILE NAME: matrices.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef MATRICES_H #ifndef MATRICES_H
#define MATRICES_H #define MATRICES_H
#include "matrix.h" #include "matrix.h"
#include "colmatrix.h" #include "colmatrix.h"
#include "rowmatrix.h" #include "rowmatrix.h"
#include "mat3x3.h" #include "mat3x3.h"
#include "vect3.h" #include "vect3.h"
#include "mat4x4.h" #include "mat4x4.h"
#include "vect4.h" #include "vect4.h"
#include "mat6x6.h" #include "mat6x6.h"
#include "vect6.h" #include "vect6.h"
#include "colmatmap.h" #include "colmatmap.h"
#endif #endif

View File

@ -1,59 +1,59 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: nrom.cpp * * FILE NAME: nrom.cpp *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#include <cmath> #include <cmath>
#include "norm.h" #include "norm.h"
double Magnitude(ColMatrix& A){ double Magnitude(ColMatrix& A){
double G; double G;
G = 0; G = 0;
for (int i=1;i<=A.GetNumRows();i++) G += A.Get(i)*A.Get(i); for (int i=1;i<=A.GetNumRows();i++) G += A.Get(i)*A.Get(i);
G = sqrt(G); G = sqrt(G);
return G; return G;
} }
double Magnitude(RowMatrix& A){ double Magnitude(RowMatrix& A){
double G; double G;
G = 0; G = 0;
for (int i=1;i<=A.GetNumCols();i++) G += A.Get(i)*A.Get(i); for (int i=1;i<=A.GetNumCols();i++) G += A.Get(i)*A.Get(i);
G = sqrt(G); G = sqrt(G);
return G; return G;
} }
double Magnitude(Vect3& A){ double Magnitude(Vect3& A){
double G; double G;
G = 0; G = 0;
for (int i=1;i<=3;i++) G += A.Get(i)*A.Get(i); for (int i=1;i<=3;i++) G += A.Get(i)*A.Get(i);
G = sqrt(G); G = sqrt(G);
return G; return G;
} }
double Magnitude(Vect4& A){ double Magnitude(Vect4& A){
double G; double G;
G = 0; G = 0;
for (int i=1;i<=4;i++) G += A.Get(i)*A.Get(i); for (int i=1;i<=4;i++) G += A.Get(i)*A.Get(i);
G = sqrt(G); G = sqrt(G);
return G; return G;
} }
double Magnitude(Vect6& A){ double Magnitude(Vect6& A){
double G; double G;
G = 0; G = 0;
for (int i=1;i<=6;i++) G += A.Get(i)*A.Get(i); for (int i=1;i<=6;i++) G += A.Get(i)*A.Get(i);
G = sqrt(G); G = sqrt(G);
return G; return G;
} }

View File

@ -1,30 +1,30 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: norm.h * * FILE NAME: norm.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef NORM_H #ifndef NORM_H
#define NORM_H #define NORM_H
#include "matrices.h" #include "matrices.h"
double Magnitude(ColMatrix& A); double Magnitude(ColMatrix& A);
double Magnitude(RowMatrix& A); double Magnitude(RowMatrix& A);
double Magnitude(Vect3& A); double Magnitude(Vect3& A);
double Magnitude(Vect4& A); double Magnitude(Vect4& A);
double Magnitude(Vect6& A); double Magnitude(Vect6& A);
#endif #endif

View File

@ -1,162 +1,162 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: poemsnodelib.h * * FILE NAME: poemsnodelib.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef NODELIB_H #ifndef NODELIB_H
#define NODELIB_H #define NODELIB_H
#include <iostream> #include <iostream>
using namespace std; using namespace std;
TreeNode *GetTreeNode(int item,TreeNode *lptr = NULL,TreeNode *rptr =NULL); TreeNode *GetTreeNode(int item,TreeNode *lptr = NULL,TreeNode *rptr =NULL);
void FreeTreeNode(TreeNode *p); void FreeTreeNode(TreeNode *p);
void Postorder(TreeNode *t, void visit(TreeNode* &t)); void Postorder(TreeNode *t, void visit(TreeNode* &t));
void Preorder (TreeNode *t, void visit(TreeNode* &t)); void Preorder (TreeNode *t, void visit(TreeNode* &t));
void CountLeaf (TreeNode *t, int& count); void CountLeaf (TreeNode *t, int& count);
int Depth (TreeNode *t); int Depth (TreeNode *t);
void IndentBlanks(int num); void IndentBlanks(int num);
void PrintTree (TreeNode *t, int level); void PrintTree (TreeNode *t, int level);
// ---------------- Global functions-----------------// // ---------------- Global functions-----------------//
// postorder recursive scan of the nodes in a tree // postorder recursive scan of the nodes in a tree
void Postorder (TreeNode *t, void visit(TreeNode* &t)) void Postorder (TreeNode *t, void visit(TreeNode* &t))
{ {
// the recursive scan terminates on a empty subtree // the recursive scan terminates on a empty subtree
if (t != NULL) if (t != NULL)
{ {
Postorder(t->Left(), visit); // descend left Postorder(t->Left(), visit); // descend left
Postorder(t->Right(), visit); // descend right Postorder(t->Right(), visit); // descend right
visit(t); // visit the node visit(t); // visit the node
} }
} }
// preorder recursive scan of the nodes in a tree // preorder recursive scan of the nodes in a tree
void Preorder (TreeNode *t, void visit(TreeNode* &t)) void Preorder (TreeNode *t, void visit(TreeNode* &t))
{ {
// the recursive scan terminates on a empty subtree // the recursive scan terminates on a empty subtree
if (t != NULL) if (t != NULL)
{ {
visit(t); // visit the node visit(t); // visit the node
Preorder(t->Left(), visit); // descend left Preorder(t->Left(), visit); // descend left
Preorder(t->Right(), visit); // descend right Preorder(t->Right(), visit); // descend right
} }
} }
//create TreeNode object with pointer fields lptr and rptr //create TreeNode object with pointer fields lptr and rptr
// The pointers have default value NULL // The pointers have default value NULL
TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr) TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr)
{ {
TreeNode *p; TreeNode *p;
// call new to allocate the new node // call new to allocate the new node
// pass parameters lptr and rptr to the function // pass parameters lptr and rptr to the function
p = new TreeNode(item, lptr, rptr); p = new TreeNode(item, lptr, rptr);
// if insufficient memory, terminatewith an error message // if insufficient memory, terminatewith an error message
if (p == NULL) if (p == NULL)
{ {
cerr << "Memory allocation failure!\n"; cerr << "Memory allocation failure!\n";
exit(1); exit(1);
} }
// return the pointer to the system generated memory // return the pointer to the system generated memory
return p; return p;
} }
// deallocate dynamic memory associated with the node // deallocate dynamic memory associated with the node
void FreeTreeNode(TreeNode *p) void FreeTreeNode(TreeNode *p)
{ {
delete p; delete p;
} }
// the function uses the postorder scan. a visit // the function uses the postorder scan. a visit
// tests whether the node is a leaf node // tests whether the node is a leaf node
void CountLeaf (TreeNode *t, int& count) void CountLeaf (TreeNode *t, int& count)
{ {
//use postorder descent //use postorder descent
if(t !=NULL) if(t !=NULL)
{ {
CountLeaf(t->Left(), count); // descend left CountLeaf(t->Left(), count); // descend left
CountLeaf(t->Right(), count); // descend right CountLeaf(t->Right(), count); // descend right
// check if node t is a leaf node (no descendants) // check if node t is a leaf node (no descendants)
// if so, increment the variable count // if so, increment the variable count
if (t->Left() == NULL && t->Right() == NULL) if (t->Left() == NULL && t->Right() == NULL)
count++; count++;
} }
} }
// the function uses the postorder scan. it computes the // the function uses the postorder scan. it computes the
// depth of the left and right subtrees of a node and // depth of the left and right subtrees of a node and
// returns the depth as 1 + max(depthLeft,depthRight). // returns the depth as 1 + max(depthLeft,depthRight).
// the depth of an empty tree is -1 // the depth of an empty tree is -1
int Depth (TreeNode *t) int Depth (TreeNode *t)
{ {
int depthLeft, depthRight, depthval; int depthLeft, depthRight, depthval;
if (t == NULL) if (t == NULL)
depthval = -1; depthval = -1;
else else
{ {
depthLeft = Depth(t->Left()); depthLeft = Depth(t->Left());
depthRight = Depth(t->Right()); depthRight = Depth(t->Right());
depthval = 1+(depthLeft > depthRight?depthLeft:depthRight); depthval = 1+(depthLeft > depthRight?depthLeft:depthRight);
} }
return depthval; return depthval;
} }
void IndentBlanks(int num) void IndentBlanks(int num)
{ {
// const int indentblock = 6; // const int indentblock = 6;
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
cout << " "; cout << " ";
} }
void PrintTree (TreeNode *t, int level) void PrintTree (TreeNode *t, int level)
{ {
//print tree with root t, as long as t!=NULL //print tree with root t, as long as t!=NULL
if (t != NULL) if (t != NULL)
{ {
int indentUnit = 5; int indentUnit = 5;
// print right branch of tree t // print right branch of tree t
PrintTree(t->Right(),level + 1); PrintTree(t->Right(),level + 1);
// indent to current level; output node data // indent to current level; output node data
IndentBlanks(indentUnit*level); IndentBlanks(indentUnit*level);
cout << t->GetData() << endl; cout << t->GetData() << endl;
// print left branch of tree t // print left branch of tree t
PrintTree(t->Left(),level + 1); PrintTree(t->Left(),level + 1);
} }
} }
#endif #endif

View File

@ -1,135 +1,135 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: vect4.cpp * * FILE NAME: vect4.cpp *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#include "vect4.h" #include "vect4.h"
using namespace std; using namespace std;
Vect4::Vect4(){ Vect4::Vect4(){
numrows = 4; numcols = 1; numrows = 4; numcols = 1;
} }
Vect4::~Vect4(){ Vect4::~Vect4(){
} }
Vect4::Vect4(const Vect4& A){ // copy constructor Vect4::Vect4(const Vect4& A){ // copy constructor
numrows = 4; numcols = 1; numrows = 4; numcols = 1;
elements[0] = A.elements[0]; elements[0] = A.elements[0];
elements[1] = A.elements[1]; elements[1] = A.elements[1];
elements[2] = A.elements[2]; elements[2] = A.elements[2];
elements[3] = A.elements[3]; elements[3] = A.elements[3];
} }
Vect4::Vect4(const VirtualMatrix& A){ // copy constructor Vect4::Vect4(const VirtualMatrix& A){ // copy constructor
numrows = 4; numcols = 1; numrows = 4; numcols = 1;
// error check // error check
if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){ if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){
cerr << "illegal matrix size" << endl; cerr << "illegal matrix size" << endl;
exit(0); exit(0);
} }
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
elements[i] = A.BasicGet(i,0); elements[i] = A.BasicGet(i,0);
} }
double& Vect4::operator_1int (int i){ // array access double& Vect4::operator_1int (int i){ // array access
return elements[i-1]; return elements[i-1];
} }
double Vect4::Get_1int(int i) const{ double Vect4::Get_1int(int i) const{
return elements[i-1]; return elements[i-1];
} }
void Vect4::Set_1int(int i, double value){ void Vect4::Set_1int(int i, double value){
elements[i-1] = value; elements[i-1] = value;
} }
double Vect4::BasicGet_1int(int i) const{ double Vect4::BasicGet_1int(int i) const{
return elements[i]; return elements[i];
} }
void Vect4::BasicSet_1int(int i, double value){ void Vect4::BasicSet_1int(int i, double value){
elements[i] = value; elements[i] = value;
} }
void Vect4::BasicIncrement_1int(int i, double value){ void Vect4::BasicIncrement_1int(int i, double value){
elements[i] += value; elements[i] += value;
} }
void Vect4::Const(double value){ void Vect4::Const(double value){
elements[0] = value; elements[0] = value;
elements[1] = value; elements[1] = value;
elements[2] = value; elements[2] = value;
elements[3] = value; elements[3] = value;
} }
MatrixType Vect4::GetType() const{ MatrixType Vect4::GetType() const{
return VECT4; return VECT4;
} }
istream& Vect4::ReadData(istream& c){ //input istream& Vect4::ReadData(istream& c){ //input
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
c >> elements[i]; c >> elements[i];
return c; return c;
} }
ostream& Vect4::WriteData(ostream& c) const{ //output ostream& Vect4::WriteData(ostream& c) const{ //output
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
c << elements[i] << ' '; c << elements[i] << ' ';
return c; return c;
} }
void Vect4::AssignVM(const VirtualMatrix& A){ void Vect4::AssignVM(const VirtualMatrix& A){
// error check // error check
if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){ if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){
cerr << "illegal matrix size" << endl; cerr << "illegal matrix size" << endl;
exit(0); exit(0);
} }
for(int i=0;i<numrows;i++) for(int i=0;i<numrows;i++)
elements[i] = A.BasicGet(i,0); elements[i] = A.BasicGet(i,0);
} }
Vect4& Vect4::operator=(const Vect4& A){ // assignment operator Vect4& Vect4::operator=(const Vect4& A){ // assignment operator
elements[0] = A.elements[0]; elements[0] = A.elements[0];
elements[1] = A.elements[1]; elements[1] = A.elements[1];
elements[2] = A.elements[2]; elements[2] = A.elements[2];
elements[3] = A.elements[3]; elements[3] = A.elements[3];
return *this; return *this;
} }
Vect4& Vect4::operator=(const VirtualMatrix& A){ // overloaded = Vect4& Vect4::operator=(const VirtualMatrix& A){ // overloaded =
// error check // error check
if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){ if( (A.GetNumRows() != 4) || (A.GetNumCols() != 1) ){
cerr << "illegal matrix size" << endl; cerr << "illegal matrix size" << endl;
exit(0); exit(0);
} }
for(int i=0;i<numrows;i++) for(int i=0;i<numrows;i++)
elements[i] = A.BasicGet(i,0); elements[i] = A.BasicGet(i,0);
return *this; return *this;
} }
Vect4& Vect4::operator*=(double b){ Vect4& Vect4::operator*=(double b){
elements[0] *= b; elements[0] *= b;
elements[1] *= b; elements[1] *= b;
elements[2] *= b; elements[2] *= b;
elements[3] *= b; elements[3] *= b;
return *this; return *this;
} }

View File

@ -1,71 +1,71 @@
/* /*
*_________________________________________________________________________* *_________________________________________________________________________*
* POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE * * POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE *
* DESCRIPTION: SEE READ-ME * * DESCRIPTION: SEE READ-ME *
* FILE NAME: vect4.h * * FILE NAME: vect4.h *
* AUTHORS: See Author List * * AUTHORS: See Author List *
* GRANTS: See Grants List * * GRANTS: See Grants List *
* COPYRIGHT: (C) 2005 by Authors as listed in Author's List * * COPYRIGHT: (C) 2005 by Authors as listed in Author's List *
* LICENSE: Please see License Agreement * * LICENSE: Please see License Agreement *
* DOWNLOAD: Free at www.rpi.edu/~anderk5 * * DOWNLOAD: Free at www.rpi.edu/~anderk5 *
* ADMINISTRATOR: Prof. Kurt Anderson * * ADMINISTRATOR: Prof. Kurt Anderson *
* Computational Dynamics Lab * * Computational Dynamics Lab *
* Rensselaer Polytechnic Institute * * Rensselaer Polytechnic Institute *
* 110 8th St. Troy NY 12180 * * 110 8th St. Troy NY 12180 *
* CONTACT: anderk5@rpi.edu * * CONTACT: anderk5@rpi.edu *
*_________________________________________________________________________*/ *_________________________________________________________________________*/
#ifndef VECT4_H #ifndef VECT4_H
#define VECT4_H #define VECT4_H
#include "virtualcolmatrix.h" #include "virtualcolmatrix.h"
class Matrix; class Matrix;
class Mat4x4; class Mat4x4;
class Vect4 : public VirtualColMatrix { class Vect4 : public VirtualColMatrix {
double elements[4]; double elements[4];
public: public:
Vect4(); Vect4();
~Vect4(); ~Vect4();
Vect4(const Vect4& A); // copy constructor Vect4(const Vect4& A); // copy constructor
Vect4(const VirtualMatrix& A); // copy constructor Vect4(const VirtualMatrix& A); // copy constructor
double& operator_1int(int i); // array access double& operator_1int(int i); // array access
double Get_1int(int i) const; double Get_1int(int i) const;
void Set_1int(int i, double value); void Set_1int(int i, double value);
double BasicGet_1int(int i) const; double BasicGet_1int(int i) const;
void BasicSet_1int(int i, double value); void BasicSet_1int(int i, double value);
void BasicIncrement_1int(int i, double value); void BasicIncrement_1int(int i, double value);
void Const(double value); void Const(double value);
MatrixType GetType() const; MatrixType GetType() const;
std::ostream& WriteData(std::ostream& c) const; std::ostream& WriteData(std::ostream& c) const;
std::istream& ReadData(std::istream& c); std::istream& ReadData(std::istream& c);
void AssignVM(const VirtualMatrix& A); void AssignVM(const VirtualMatrix& A);
Vect4& operator=(const Vect4& A); // assignment operator Vect4& operator=(const Vect4& A); // assignment operator
Vect4& operator=(const VirtualMatrix& A); // overloaded = Vect4& operator=(const VirtualMatrix& A); // overloaded =
Vect4& operator*=(double b); Vect4& operator*=(double b);
friend Matrix T(const Vect4& A); // a wasteful transpose friend Matrix T(const Vect4& A); // a wasteful transpose
friend Mat4x4 CrossMat(Vect4& a); // a wasteful cross matrix implementation friend Mat4x4 CrossMat(Vect4& a); // a wasteful cross matrix implementation
// fast matrix functions // fast matrix functions
friend void FastAssign(Vect4& a, Vect4& c); friend void FastAssign(Vect4& a, Vect4& c);
friend void FastSimpleRotation(Vect4& v, double q, Mat4x4& d); friend void FastSimpleRotation(Vect4& v, double q, Mat4x4& d);
friend void FastCross(Vect4& a, Vect4& b, Vect4& c); // cross product axb = c friend void FastCross(Vect4& a, Vect4& b, Vect4& c); // cross product axb = c
friend void FastTripleSum(Vect4& a, Vect4& b, Vect4& c, Vect4& d); friend void FastTripleSum(Vect4& a, Vect4& b, Vect4& c, Vect4& d);
friend void FastTripleSumPPM(Vect4& a, Vect4& b, Vect4& c, Vect4& d); friend void FastTripleSumPPM(Vect4& a, Vect4& b, Vect4& c, Vect4& d);
friend void FastMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastTMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastTMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastNegMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastNegMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastNegTMult(Mat4x4& A, Vect4& B, Vect4& C); friend void FastNegTMult(Mat4x4& A, Vect4& B, Vect4& C);
friend void FastMult(double a, Vect4& B, Vect4& C); friend void FastMult(double a, Vect4& B, Vect4& C);
friend void FastAdd(Vect4& A, Vect4& B, Vect4& C); friend void FastAdd(Vect4& A, Vect4& B, Vect4& C);
friend void FastSubt(Vect4& A, Vect4& B, Vect4& C); friend void FastSubt(Vect4& A, Vect4& B, Vect4& C);
}; };
#endif #endif

View File

@ -1,22 +1,22 @@
# GaN potential: A. Bere, and A. Serra, Phil. Mag. 86, 2159(2006) # GaN potential: A. Bere, and A. Serra, Phil. Mag. 86, 2159(2006)
# note that the parameters for this literature potential are pairwise # note that the parameters for this literature potential are pairwise
# so that there are some flexibility in the way the # so that there are some flexibility in the way the
# parameters can be entered. As one way, we assume that # parameters can be entered. As one way, we assume that
# lambda_ijk is equal to lambda_ik and eps_ijk is # lambda_ijk is equal to lambda_ik and eps_ijk is
# equal to sqrt(lambda_ij*eps_ij*lambda_ik*eps_ik)/lambda_ik, # equal to sqrt(lambda_ij*eps_ij*lambda_ik*eps_ik)/lambda_ik,
# and all other parameters in the ijk line are for ik. # and all other parameters in the ijk line are for ik.
# These entries are in LAMMPS "metal" units: # These entries are in LAMMPS "metal" units:
# epsilon = eV; sigma = Angstroms # epsilon = eV; sigma = Angstroms
# other quantities are unitless # other quantities are unitless
# #
# eps sigma a lambda gamma cos(theta) A B p q tol # eps sigma a lambda gamma cos(theta) A B p q tol
# #
Ga Ga Ga 1.2000000 2.100 1.6 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 Ga Ga Ga 1.2000000 2.100 1.6 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
N N N 1.2000000 1.300 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 N N N 1.2000000 1.300 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
Ga Ga N 1.6136914 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 Ga Ga N 1.6136914 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
Ga N N 2.1700000 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 Ga N N 2.1700000 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
N Ga Ga 2.1700000 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 N Ga Ga 2.1700000 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
N Ga N 1.6136914 1.300 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 N Ga N 1.6136914 1.300 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
N N Ga 1.6136914 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 N N Ga 1.6136914 1.695 1.8 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0
Ga N Ga 1.6136914 2.100 1.6 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0 Ga N Ga 1.6136914 2.100 1.6 32.5 1.2 -0.333333333333 7.917 0.72 4.0 0.0 0.0

View File

@ -1,17 +1,17 @@
# Stillinger-Weber parameters for various elements and mixtures # Stillinger-Weber parameters for various elements and mixtures
# multiple entries can be added to this file, LAMMPS reads the ones it needs # multiple entries can be added to this file, LAMMPS reads the ones it needs
# these entries are in LAMMPS "metal" units: # these entries are in LAMMPS "metal" units:
# epsilon = eV; sigma = Angstroms # epsilon = eV; sigma = Angstroms
# other quantities are unitless # other quantities are unitless
# format of a single entry (one or more lines): # format of a single entry (one or more lines):
# element 1, element 2, element 3, # element 1, element 2, element 3,
# epsilon, sigma, a, lambda, gamma, costheta0, A, B, p, q, tol # epsilon, sigma, a, lambda, gamma, costheta0, A, B, p, q, tol
# Here are the original parameters in metal units, for Silicon from: # Here are the original parameters in metal units, for Silicon from:
# #
# Stillinger and Weber, Phys. Rev. B, v. 31, p. 5262, (1985) # Stillinger and Weber, Phys. Rev. B, v. 31, p. 5262, (1985)
# #
Si Si Si 2.1683 2.0951 1.80 21.0 1.20 -0.333333333333 Si Si Si 2.1683 2.0951 1.80 21.0 1.20 -0.333333333333
7.049556277 0.6022245584 4.0 0.0 0.0 7.049556277 0.6022245584 4.0 0.0 0.0

View File

@ -1,51 +1,51 @@
//This code was written by Philip Nicoletti //This code was written by Philip Nicoletti
//http://www.codeguru.com/forum/archive/index.php/t-129990.html //http://www.codeguru.com/forum/archive/index.php/t-129990.html
// //
//Modified by Jin Ma, Oklahoma State University for LAMMPS //Modified by Jin Ma, Oklahoma State University for LAMMPS
//erfc() is defined in GNU libraries. This code is a simplified //erfc() is defined in GNU libraries. This code is a simplified
//version for implementation with Visual C++. //version for implementation with Visual C++.
// //
//Warning: these functions are not fully tested. //Warning: these functions are not fully tested.
// //
#include "erfc.h" #include "erfc.h"
#include "math.h" #include "math.h"
double erf(double x) double erf(double x)
{ {
// //
// Computation of the error function erf(x). // Computation of the error function erf(x).
// //
return (1-erfc(x)); return (1-erfc(x));
} }
// //
// //
double erfc(double x) double erfc(double x)
{ {
// //
// Computation of the complementary error function erfc(x). // Computation of the complementary error function erfc(x).
// //
// The algorithm is based on a Chebyshev fit as denoted in // The algorithm is based on a Chebyshev fit as denoted in
// Numerical Recipes 2nd ed. on p. 214 (W.H.Press et al.). // Numerical Recipes 2nd ed. on p. 214 (W.H.Press et al.).
// //
// The fractional error is always less than 1.2e-7. // The fractional error is always less than 1.2e-7.
// //
// //
// The parameters of the Chebyshev fit // The parameters of the Chebyshev fit
// //
const double a1 = -1.26551223, a2 = 1.00002368, const double a1 = -1.26551223, a2 = 1.00002368,
a3 = 0.37409196, a4 = 0.09678418, a3 = 0.37409196, a4 = 0.09678418,
a5 = -0.18628806, a6 = 0.27886807, a5 = -0.18628806, a6 = 0.27886807,
a7 = -1.13520398, a8 = 1.48851587, a7 = -1.13520398, a8 = 1.48851587,
a9 = -0.82215223, a10 = 0.17087277; a9 = -0.82215223, a10 = 0.17087277;
// //
double v = 1; // The return value double v = 1; // The return value
double z = fabs(x); double z = fabs(x);
// //
if (z == 0) return v; // erfc(0)=1 if (z == 0) return v; // erfc(0)=1
double t = 1/(1+0.5*z); double t = 1/(1+0.5*z);
v = t*exp((-z*z) +a1+t*(a2+t*(a3+t*(a4+t*(a5+t*(a6+ v = t*exp((-z*z) +a1+t*(a2+t*(a3+t*(a4+t*(a5+t*(a6+
t*(a7+t*(a8+t*(a9+t*a10))))))))); t*(a7+t*(a8+t*(a9+t*a10)))))))));
if (x < 0) v = 2-v; // erfc(-x)=2-erfc(x) if (x < 0) v = 2-v; // erfc(-x)=2-erfc(x)
return v; return v;
} }

View File

@ -1,5 +1,5 @@
// //
double erf(double x); double erf(double x);
double erfc(double x); double erfc(double x);

View File

@ -1,126 +1,126 @@
This is instruction for the modification of LAMMPS for MS Windows This is instruction for the modification of LAMMPS for MS Windows
LAMMPS version: Feb 2007 LAMMPS version: Feb 2007
compiled without MPI and FFT in Viusal C++ 6.0 compiled without MPI and FFT in Viusal C++ 6.0
(All packages except for XTC, MEAM appear to work.) (All packages except for XTC, MEAM appear to work.)
------------------- -------------------
1. Create an empty workspace (Win32 console), add all .h and .cpp 1. Create an empty workspace (Win32 console), add all .h and .cpp
files into the project. files into the project.
2. At about 80 places in the code, variables are redefined. Most of 2. At about 80 places in the code, variables are redefined. Most of
these variables are loop counters, which can be easily fixed. these variables are loop counters, which can be easily fixed.
Code looks like this: Code looks like this:
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
something; something;
} }
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
something else; something else;
} }
This is ok with g++ compiler. But VC thinks the i is redefined in the This is ok with g++ compiler. But VC thinks the i is redefined in the
second loop. So the variable scope is different. This happens many times second loop. So the variable scope is different. This happens many times
in the code. It can be fixed easily based on the compiling error. in the code. It can be fixed easily based on the compiling error.
3. At the beginning of fft3d.h, added: 3. At the beginning of fft3d.h, added:
#ifndef FFT_NONE #ifndef FFT_NONE
#define FFT_NONE #define FFT_NONE
#endif #endif
4. In input.cpp, changed the two header files 4. In input.cpp, changed the two header files
//#include "unistd.h" //#include "unistd.h"
#include "direct.h" #include "direct.h"
4A. (added by Tim Lau, MIT, ttl@mit.edu) 4A. (added by Tim Lau, MIT, ttl@mit.edu)
In variable.cpp, change the header files In variable.cpp, change the header files
//#include "unistd.h" //#include "unistd.h"
#include "sleep.h" #include "sleep.h"
Add in the included sleep.h and sleep.cpp files. Add in the included sleep.h and sleep.cpp files.
4B. (added by Tim Lau, MIT, ttl@mit.edu) 4B. (added by Tim Lau, MIT, ttl@mit.edu)
In shell.cpp, change the header file: In shell.cpp, change the header file:
//#include "unistd.h" //#include "unistd.h"
#include "direct.h" #include "direct.h"
Change the line in shell.cpp: Change the line in shell.cpp:
mkdir(arg[i], S_IRWXU | S_IRGRP | S_IXGRP); mkdir(arg[i], S_IRWXU | S_IRGRP | S_IXGRP);
to: to:
mkdir(arg[i]); mkdir(arg[i]);
since Windows obviously does not use UNIX file permissions. since Windows obviously does not use UNIX file permissions.
It's also possible that the line has to be changed to: It's also possible that the line has to be changed to:
_mkdir(arg[i]); _mkdir(arg[i]);
depending on the version of the Visual C++ compiler used. depending on the version of the Visual C++ compiler used.
5. Added mpi.h and mpi.cpp (in STUBS folder) to the workspace 5. Added mpi.h and mpi.cpp (in STUBS folder) to the workspace
In mpi.cpp, commented the time.h header file In mpi.cpp, commented the time.h header file
//#include <sys/time.h> //#include <sys/time.h>
commented the original code in MPI_Wtime(), just make it return 0; commented the original code in MPI_Wtime(), just make it return 0;
6. In system.cpp, two changes due to difference in the input argument 6. In system.cpp, two changes due to difference in the input argument
list list
Line 83: int iarg = 2; Line 83: int iarg = 2;
Line 172: inflag=1; //add this line Line 172: inflag=1; //add this line
The number of input arguments (nargs) is different in g++ and VC when The number of input arguments (nargs) is different in g++ and VC when
you give arguments to run a program. This might be related to MPI as you give arguments to run a program. This might be related to MPI as
well. The difference is one. Once the above changes are made, the well. The difference is one. Once the above changes are made, the
program is taking the correct argument. program is taking the correct argument.
However, it has been observed in the latest versions of sytem.cpp that However, it has been observed in the latest versions of sytem.cpp that
no modification needs be made to the file as distributed from the no modification needs be made to the file as distributed from the
LAMMPS website to work. The user however, instead of starting LAMMPS LAMMPS website to work. The user however, instead of starting LAMMPS
by the command: by the command:
lammps in.file lammps in.file
as he would if he implemented the changes detailed here, would launch as he would if he implemented the changes detailed here, would launch
in the Unix style: in the Unix style:
lammps < in.file lammps < in.file
7. The new version LAMMPS calls the error function: 7. The new version LAMMPS calls the error function:
double erfc(double) double erfc(double)
This function is in the GNU C library. However, it's not found for This function is in the GNU C library. However, it's not found for
VC++. VC++.
Three options: Three options:
a. One can try to find erfc() from other libraries. a. One can try to find erfc() from other libraries.
b. The erfc() is called for pair_modify table option. One can set b. The erfc() is called for pair_modify table option. One can set
the table option to be 0 to avoid calling this function. the table option to be 0 to avoid calling this function.
c. Write your own functions. c. Write your own functions.
In this code, two files erfc.h, erfc.cpp are created and added to the project. In this code, two files erfc.h, erfc.cpp are created and added to the project.
Files that call erfc() all add Files that call erfc() all add
#include "erfc.h" at the beginning. #include "erfc.h" at the beginning.
Note: the functions are not fully tested, use with caution. Note: the functions are not fully tested, use with caution.
8. MSVC does not have a inttypes.h file. The simplest way 8. MSVC does not have a inttypes.h file. The simplest way
to deal with this problem is to download inttypes.h from the to deal with this problem is to download inttypes.h from the
following site: following site:
http://www.koders.com/c/fidDE7D6EFFD475FAB1B7F6A2BBA791401CFA88FFA3.aspx http://www.koders.com/c/fidDE7D6EFFD475FAB1B7F6A2BBA791401CFA88FFA3.aspx
and add this file into the workspace. and add this file into the workspace.
9. MSVC does not have dirent.h. The problem is solved by downloading 9. MSVC does not have dirent.h. The problem is solved by downloading
a version of it for Windows from the following website: a version of it for Windows from the following website:
http://www.softagalleria.net/dirent/index.en.html http://www.softagalleria.net/dirent/index.en.html
10. Every time an error pops up for a line like this: 10. Every time an error pops up for a line like this:
char *words[params_per_line]; char *words[params_per_line];
replace to the following type: replace to the following type:
char **words = new char*[params_per_line]; char **words = new char*[params_per_line];
The dynamic memory allocation in MSVC requires a line like this. The dynamic memory allocation in MSVC requires a line like this.
11. Build the project. Specify appropriate input file to run the code. 11. Build the project. Specify appropriate input file to run the code.
The Windows result might be different from Unix results. Be Cautious. The Windows result might be different from Unix results. Be Cautious.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +1,82 @@
README.txt README.txt
lmp2cfg lmp2cfg
Version 1.0 Version 1.0
Ara Kooser Ara Kooser
8/1/04 8/1/04
Contents Contents
I. Before you start I. Before you start
II. Introduction II. Introduction
III. Compiling the program III. Compiling the program
IV. Running the program IV. Running the program
I. Before you start I. Before you start
1) Read the READMEFIRST file 1) Read the READMEFIRST file
2) You will need either f77 or g77 compiler 2) You will need either f77 or g77 compiler
3) A text editor (VI or emacs) 3) A text editor (VI or emacs)
4) AtomEye( http://164.107.79.177/Archive/Graphics/A/) good as of 8/1/04 4) AtomEye( http://164.107.79.177/Archive/Graphics/A/) good as of 8/1/04
5) A sense of adventure and humor 5) A sense of adventure and humor
II. Introduction II. Introduction
The lmp2cfg program converts a LAMMPS atom dump file into a series of .cfg The lmp2cfg program converts a LAMMPS atom dump file into a series of .cfg
files.(000001.cfg, 000002.cfg,...). These files can be read into AtomEye files.(000001.cfg, 000002.cfg,...). These files can be read into AtomEye
and made into a movie or viewed indivdually. and made into a movie or viewed indivdually.
III. Compiling the program III. Compiling the program
The program should comply with either command f77 lmp2cfg.f or The program should comply with either command f77 lmp2cfg.f or
g77 lmp2cfg.f g77 lmp2cfg.f
IV. Running the program IV. Running the program
You need to create a user input file. In the examples folder you will find You need to create a user input file. In the examples folder you will find
an example input script, LAMMPS dump file, and the correct .cfg output. an example input script, LAMMPS dump file, and the correct .cfg output.
The input script reads like this: The input script reads like this:
7 #number of atom types in your LAMMPS file 7 #number of atom types in your LAMMPS file
'dump.atom' #name of the LAMMPS dump file, you need the ' ' 'dump.atom' #name of the LAMMPS dump file, you need the ' '
1 #first frame 1 #first frame
10 #last frame 10 #last frame
1 #first atom type 1 #first atom type
26.98154 #atomic weight 26.98154 #atomic weight
'ao' #atom name 'ao' #atom name
2 #second atom type 2 #second atom type
15.9994 #atomic weight 15.9994 #atomic weight
'oh' #atom name 'oh' #atom name
Make sure the input file and the atom dump file are in the same folder. Make sure the input file and the atom dump file are in the same folder.
On the command line type On the command line type
lmp2cfg < input_file.txt > out lmp2cfg < input_file.txt > out
You should get several .cfg files. For reading into AtomEye and making You should get several .cfg files. For reading into AtomEye and making
movies see the AtomEye homepage. movies see the AtomEye homepage.
If you get an error like: If you get an error like:
open: 'new' file exists open: 'new' file exists
apparent state: unit 21 named 00001.cfg apparent state: unit 21 named 00001.cfg
lately writing sequential formatted external IO lately writing sequential formatted external IO
Abort Abort
you need to first remove old copies of the cfg files. you need to first remove old copies of the cfg files.
If you get an error like: If you get an error like:
open: No such file or directory open: No such file or directory
apparent state: unit 9 named dump.atom apparent state: unit 9 named dump.atom
last format: list io last format: list io
lately reading direct formatted external IO lately reading direct formatted external IO
Abort Abort
you need to check that the name of the dump file matches the name you need to check that the name of the dump file matches the name
in the input file, and that you enclosed it in single quotes. in the input file, and that you enclosed it in single quotes.

View File

@ -1,25 +1,25 @@
7 7
'dump.atom' 'dump.atom'
1 1
3 3
1 1
26.98154 26.98154
'ao' 'ao'
2 2
15.9994 15.9994
'oh' 'oh'
3 3
1.00794 1.00794
'ho' 'ho'
4 4
15.9994 15.9994
'o*' 'o*'
5 5
1.00794 1.00794
'h*' 'h*'
6 6
35.4527 35.4527
'Cl' 'Cl'
7 7
207.2 207.2
'Pb' 'Pb'

View File

@ -1,181 +1,181 @@
*23456789|123456789|123456789|123456789|123456789|123456789|123456789|12 *23456789|123456789|123456789|123456789|123456789|123456789|123456789|12
c---------------------------------------------------------------------- c----------------------------------------------------------------------
program lammps to cfg program lammps to cfg
c---------------------------------------------------------------------- c----------------------------------------------------------------------
*Programming by Jeff Greathouse and Ara Kooser *Programming by Jeff Greathouse and Ara Kooser
*Version 1.0 9/1/04 *Version 1.0 9/1/04
*Sandia National Labs *Sandia National Labs
*Converts LAMMPS atom dump to .cfg files for AtomEye *Converts LAMMPS atom dump to .cfg files for AtomEye
*This program is provided as is. Please see the README file. *This program is provided as is. Please see the README file.
c---------------------------------------------------------------------- c----------------------------------------------------------------------
implicit real*8 (a-h,o-z) implicit real*8 (a-h,o-z)
character*12 inhist,snapshot character*12 inhist,snapshot
character*4 fftype(100),name,ciframe character*4 fftype(100),name,ciframe
integer natom,iatom,itype(50000),q integer natom,iatom,itype(50000),q
integer atype(99),itycon,ntype,mass(99) integer atype(99),itycon,ntype,mass(99)
dimension x(50000),y(50000),z(50000) dimension x(50000),y(50000),z(50000)
dimension amass(99) dimension amass(99)
c-------Reads in the user input file------------------------------- c-------Reads in the user input file-------------------------------
read(*,*) ntype read(*,*) ntype
read(*,*) inhist read(*,*) inhist
read(*,*) iframe1 read(*,*) iframe1
read(*,*) iframe2 read(*,*) iframe2
c write(*,*) ntype c write(*,*) ntype
c write(*,*) inhist c write(*,*) inhist
do 1, i=1, ntype do 1, i=1, ntype
read(*,*) atype(i) read(*,*) atype(i)
read(*,*) amass(i) read(*,*) amass(i)
mass(i)=anint(amass(i)) mass(i)=anint(amass(i))
read(*,*) fftype(i) read(*,*) fftype(i)
c write(*,*) atype(i) c write(*,*) atype(i)
c write(*,*) amass(i) c write(*,*) amass(i)
c write(*,*) fftype(i) c write(*,*) fftype(i)
1 continue 1 continue
c-------Lammps output file is 9, reads in lmps header-------------- c-------Lammps output file is 9, reads in lmps header--------------
name=inhist(1:4) name=inhist(1:4)
open(9,file=inhist,status='old',form='formatted') open(9,file=inhist,status='old',form='formatted')
c open(2,status='new',form='formatted') c open(2,status='new',form='formatted')
iatom=0 iatom=0
iframe=0 iframe=0
jframe=0 jframe=0
c--------------------------------------------------------------------- c---------------------------------------------------------------------
c----------This begins the frame by frame reading section------------- c----------This begins the frame by frame reading section-------------
9999 continue 9999 continue
read(9,*,end=999) read(9,*,end=999)
read(9,*,end=999) read(9,*,end=999)
read(9,*,end=999) read(9,*,end=999)
read(9,*,end=999) natom read(9,*,end=999) natom
read(9,*,end=999) read(9,*,end=999)
read(9,50,end=999) xcell read(9,50,end=999) xcell
read(9,50,end=999) ycell read(9,50,end=999) ycell
read(9,50,end=999) zcell read(9,50,end=999) zcell
read(9,*,end=999) read(9,*,end=999)
50 format(2x,f12.5) 50 format(2x,f12.5)
1000 format(1x,i5,1x,i2,3f9.5) 1000 format(1x,i5,1x,i2,3f9.5)
do 440 j=1,natom do 440 j=1,natom
420 read(9,*,end=999)iatom,itype(iatom),x(iatom),y(iatom),z(iatom) 420 read(9,*,end=999)iatom,itype(iatom),x(iatom),y(iatom),z(iatom)
*23456789|123456789|123456789|123456789|123456789|123456789|123456789|12 *23456789|123456789|123456789|123456789|123456789|123456789|123456789|12
440 continue 440 continue
jframe=jframe+1 jframe=jframe+1
if(jframe.lt.iframe1)goto 9999 if(jframe.lt.iframe1)goto 9999
iframe=iframe+1 iframe=iframe+1
if(iframe.ge.iframe2) goto 999 if(iframe.ge.iframe2) goto 999
c-------------------------------------------------------------------- c--------------------------------------------------------------------
c-------This section writes each ts to a seperate .cfg file---------- c-------This section writes each ts to a seperate .cfg file----------
c ciframe=char(iframe) c ciframe=char(iframe)
c snapshot(iframe)=name//ciframe//'.cfg' c snapshot(iframe)=name//ciframe//'.cfg'
c write(*,*)ciframe c write(*,*)ciframe
c write(snapshot,'("Cfgs/",i7.7,".cfg")') iframe c write(snapshot,'("Cfgs/",i7.7,".cfg")') iframe
ciframe='.cfg' ciframe='.cfg'
c write(*,*)ciframe c write(*,*)ciframe
write(snapshot,'(i5.5,a4)')iframe,ciframe write(snapshot,'(i5.5,a4)')iframe,ciframe
c write(*,*)snapshot c write(*,*)snapshot
open(unit=iframe+20,file=snapshot,status='new', open(unit=iframe+20,file=snapshot,status='new',
* form='formatted') * form='formatted')
write((iframe+20),'(a22,i7)')'Number of particles = ',natom write((iframe+20),'(a22,i7)')'Number of particles = ',natom
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a16)')'A = 1.0 Angstrom' write((iframe+20),'(a16)')'A = 1.0 Angstrom'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),435)'H0(1,1) = ',xcell,' A' write((iframe+20),435)'H0(1,1) = ',xcell,' A'
write((iframe+20),'(a14)')'H0(1,2) = 0 A' write((iframe+20),'(a14)')'H0(1,2) = 0 A'
write((iframe+20),'(a14)')'H0(1,3) = 0 A' write((iframe+20),'(a14)')'H0(1,3) = 0 A'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a14)')'H0(2,1) = 0 A' write((iframe+20),'(a14)')'H0(2,1) = 0 A'
write((iframe+20),435)'H0(2,2) = ',ycell,' A' write((iframe+20),435)'H0(2,2) = ',ycell,' A'
write((iframe+20),'(a14)')'H0(2,3) = 0 A' write((iframe+20),'(a14)')'H0(2,3) = 0 A'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a14)')'H0(3,1) = 0 A' write((iframe+20),'(a14)')'H0(3,1) = 0 A'
write((iframe+20),'(a14)')'H0(3,2) = 0 A' write((iframe+20),'(a14)')'H0(3,2) = 0 A'
write((iframe+20),435)'H0(3,3) = ',zcell,' A' write((iframe+20),435)'H0(3,3) = ',zcell,' A'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a12)')'eta(1,1) = 0' write((iframe+20),'(a12)')'eta(1,1) = 0'
write((iframe+20),'(a12)')'eta(1,2) = 0' write((iframe+20),'(a12)')'eta(1,2) = 0'
write((iframe+20),'(a12)')'eta(1,3) = 0' write((iframe+20),'(a12)')'eta(1,3) = 0'
write((iframe+20),'(a12)')'eta(2,2) = 0' write((iframe+20),'(a12)')'eta(2,2) = 0'
write((iframe+20),'(a12)')'eta(2,3) = 0' write((iframe+20),'(a12)')'eta(2,3) = 0'
write((iframe+20),'(a12)')'eta(3,3) = 0' write((iframe+20),'(a12)')'eta(3,3) = 0'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),*) write((iframe+20),*)
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
write((iframe+20),'(a1)')'#' write((iframe+20),'(a1)')'#'
435 format(a11,f10.5,a2) 435 format(a11,f10.5,a2)
do 460, j=1,natom do 460, j=1,natom
do 450,i=1,ntype do 450,i=1,ntype
c write(*,*)i,amass(i),fftype(i) c write(*,*)i,amass(i),fftype(i)
c write(*,*)ntype c write(*,*)ntype
if(itype(j).eq.atype(i)) if(itype(j).eq.atype(i))
* write((iframe+20),445)mass(i),fftype(i),x(j), * write((iframe+20),445)mass(i),fftype(i),x(j),
* y(j),z(j),' 0',' 0',' 0' * y(j),z(j),' 0',' 0',' 0'
c---445 is the format for writing atom data to .cfg file------------ c---445 is the format for writing atom data to .cfg file------------
445 format(i3.3,1x,a2,1x,3f9.6,3a2) 445 format(i3.3,1x,a2,1x,3f9.6,3a2)
450 continue 450 continue
460 continue 460 continue
go to 9999 go to 9999
999 continue 999 continue
close(9) close(9)
end end

View File

@ -1,78 +1,78 @@
README.txt README.txt
lmp2traj lmp2traj
Version 1.0 Version 1.0
Ara Kooser Ara Kooser
8/1/04 8/1/04
Contents Contents
I. Before you start I. Before you start
II. Introduction II. Introduction
III. Compiling the program III. Compiling the program
IV. Running the program IV. Running the program
I. Before you start I. Before you start
1) Read the READMEFIRST file 1) Read the READMEFIRST file
2) You will need either f77 or g77 compiler 2) You will need either f77 or g77 compiler
3) A text editor (VI or emacs) 3) A text editor (VI or emacs)
4) LAMMPS 4) LAMMPS
5) A graphing program that can do contours 5) A graphing program that can do contours
6) A sense of adventure and humor 6) A sense of adventure and humor
II. Introduction II. Introduction
This program will take a LAMMPS atom dump file and provide the following three This program will take a LAMMPS atom dump file and provide the following three
files. files.
1) data for making contour maps 1) data for making contour maps
2) density profile 2) density profile
3) dipole information 3) dipole information
III. Compiling the program III. Compiling the program
To compile the program run either ./f77 lmp2traj.f or To compile the program run either ./f77 lmp2traj.f or
./g77 traj.f ./g77 traj.f
IV. Running the program IV. Running the program
First you need to create a user input file. There is an example of an input file First you need to create a user input file. There is an example of an input file
in the examples folder. in the examples folder.
The input file reads like this: The input file reads like this:
'atom' # dump file name, needs the ' ' 'atom' # dump file name, needs the ' '
1 # first frame 1 # first frame
60 # last frame 60 # last frame
38.26119 # x dimension of the box 38.26119 # x dimension of the box
44.26119 # y dimension of the box 44.26119 # y dimension of the box
48.33150 # z dimension of the box 48.33150 # z dimension of the box
90. # angles of the box, always 90 90. # angles of the box, always 90
90. # angles of the box, always 90 90. # angles of the box, always 90
90. # angles of the box, always 90 90. # angles of the box, always 90
82844.6 # volumne of the box in cubic Angstroms 82844.6 # volumne of the box in cubic Angstroms
5 # water oxygen atom type from LAMMPS (#) 5 # water oxygen atom type from LAMMPS (#)
6 # water hydrogen atom type from LAMMPS(#) 6 # water hydrogen atom type from LAMMPS(#)
0. # leave at 0 0. # leave at 0
5. # number of atom types 5. # number of atom types
0. # z shift leave at 0 0. # z shift leave at 0
5. # number of density maps 5. # number of density maps
'Surface (1) ho' # Enter name/description of atom 'Surface (1) ho' # Enter name/description of atom
2 # atom type number from LAMMPS 2 # atom type number from LAMMPS
'ho' # Column name for data 'ho' # Column name for data
0 # Defines inner sphere, in A 0 # Defines inner sphere, in A
48.3 # Defines out sphere, in A 48.3 # Defines out sphere, in A
Make sure you have the input file and the LAMMPS atom dump file in the same Make sure you have the input file and the LAMMPS atom dump file in the same
directory. directory.
To run the program type To run the program type
lmp2traj < inp_file.txt > out lmp2traj < inp_file.txt > out
This should give you three files like in the examples/output folder. This should give you three files like in the examples/output folder.

View File

@ -1,26 +1,26 @@
'dump.atom' 'dump.atom'
1 1
3 3
29.00000 29.00000
38.26120 38.26120
44.79980 44.79980
90. 90.
90. 90.
90. 90.
49708.7291 49708.7291
1 1
2 2
0. 0.
2. 2.
0. 0.
2 2
'Bulk (1) O-water' 'Bulk (1) O-water'
1 1
'o*' 'o*'
18.6 18.6
21.0 21.0
'Bulk (1) H-water' 'Bulk (1) H-water'
2 2
'h*' 'h*'
18.1 18.1
21.5 21.5

View File

@ -1,252 +1,252 @@
function lmp2cfg(varargin) function lmp2cfg(varargin)
% Converts LAMMPS dump file to Extended CFG Format (No velocity) to be used % Converts LAMMPS dump file to Extended CFG Format (No velocity) to be used
% with AtomEye (http://164.107.79.177/Archive/Graphics/A/) % with AtomEye (http://164.107.79.177/Archive/Graphics/A/)
% Input : % Input :
% Necessary (in order) % Necessary (in order)
% timestep,Natoms,x_bound,y_bound,z_bound,H,atom_data,mass, % timestep,Natoms,x_bound,y_bound,z_bound,H,atom_data,mass,
% cfg file name, dumpfile name % cfg file name, dumpfile name
% Optional % Optional
% 'vel' --> 'yes' (if velocity data needs to be written) % 'vel' --> 'yes' (if velocity data needs to be written)
% --> Default is 'no' % --> Default is 'no'
% 'atomtype' --> {Atom symbol} % 'atomtype' --> {Atom symbol}
% 'autonumber' --> 'yes' (default) numbers cfgfiles consecutively based on timestep % 'autonumber' --> 'yes' (default) numbers cfgfiles consecutively based on timestep
% 'autolog' --> 'on' (default) writes details of conversion to a log file % 'autolog' --> 'on' (default) writes details of conversion to a log file
% 'rotation' --> To specify rotation (Transform in cfg file) say 'rotation' followed by % 'rotation' --> To specify rotation (Transform in cfg file) say 'rotation' followed by
% number of rotations,the axes of rotation ('X' or 'Y' or 'Z')and the % number of rotations,the axes of rotation ('X' or 'Y' or 'Z')and the
% angle in degrees. CAUTION : Do remember that rotations are % angle in degrees. CAUTION : Do remember that rotations are
% non-commutative and hence the order of rotations must be the same as % non-commutative and hence the order of rotations must be the same as
% intended % intended
% 'aux' --> Auxiliary data must be a two column array with Quantity and Type in each % 'aux' --> Auxiliary data must be a two column array with Quantity and Type in each
% column % column
% %
% %
% THE DATA MUST BE SCALED (0 to 1)IN ORDER FOR ATOMEYE TO READ PROPERLY % THE DATA MUST BE SCALED (0 to 1)IN ORDER FOR ATOMEYE TO READ PROPERLY
% Real coordinates x = s * H, x, s are 1x3 row vectors % Real coordinates x = s * H, x, s are 1x3 row vectors
% %
% Example % Example
% lmp2cfg_all(data.timestep,data.Natoms,data.xbound,data.ybound,... % lmp2cfg_all(data.timestep,data.Natoms,data.xbound,data.ybound,...
% data.zbound,H,data.atom_data,mass,cfgfile,dumpfile,... % data.zbound,H,data.atom_data,mass,cfgfile,dumpfile,...
% 'vel','no','aux',{'sxx' 'Lammps O/P' % 'vel','no','aux',{'sxx' 'Lammps O/P'
% 'syy' 'Lammps O/P' % 'syy' 'Lammps O/P'
% 'szz' 'Lammps O/P' % 'szz' 'Lammps O/P'
% 'sxy' 'Lammps O/P' % 'sxy' 'Lammps O/P'
% 'sxz' 'Lammps O/P' % 'sxz' 'Lammps O/P'
% 'syz' 'Lammps O/P'},... % 'syz' 'Lammps O/P'},...
% 'atomtype',{'Ni' % 'atomtype',{'Ni'
% 'Al'},... % 'Al'},...
% 'autonumber','on',... % 'autonumber','on',...
% 'autolog','on',... % 'autolog','on',...
% 'rotation',2,'X',45,'Y',30); % 'rotation',2,'X',45,'Y',30);
% %
% See also readdump_all, readdump_one, scandump % See also readdump_all, readdump_one, scandump
% %
% Author : Arun K. Subramaniyan % Author : Arun K. Subramaniyan
% sarunkarthi@gmail.com % sarunkarthi@gmail.com
% http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm % http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm
% School of Aeronautics and Astronautics % School of Aeronautics and Astronautics
% Purdue University, West Lafayette, IN - 47907, USA. % Purdue University, West Lafayette, IN - 47907, USA.
%------------ Defaults %------------ Defaults
vel = 'no'; vel = 'no';
auxstatus = 0; auxstatus = 0;
atom_typestatus = 0; atom_typestatus = 0;
rotstatus = 0; rotstatus = 0;
autonumber_status = 1; % default is ON autonumber_status = 1; % default is ON
autolog_status = 1; autolog_status = 1;
%---------------------------------- %----------------------------------
%-----Required Input -------------- %-----Required Input --------------
timestep = varargin{1} timestep = varargin{1}
Natoms = varargin{2}; Natoms = varargin{2};
x_bound = varargin{3}; x_bound = varargin{3};
y_bound = varargin{4}; y_bound = varargin{4};
z_bound = varargin{5}; z_bound = varargin{5};
H = varargin{6}; H = varargin{6};
atom_data = varargin{7}; atom_data = varargin{7};
mass = varargin{8}; %arrange it in order of atom type , ie 1 - mass1 etc mass = varargin{8}; %arrange it in order of atom type , ie 1 - mass1 etc
filename = varargin{9}; %Just give one file name filename = varargin{9}; %Just give one file name
if length(varargin) < 10 if length(varargin) < 10
dumpfilename = ['dump.' filename]; dumpfilename = ['dump.' filename];
else else
dumpfilename = varargin{10}; dumpfilename = varargin{10};
end end
if length(varargin) > 10 if length(varargin) > 10
i=11; i=11;
while i<length(varargin) while i<length(varargin)
id = varargin{i}; id = varargin{i};
switch id switch id
case 'vel' case 'vel'
vel = varargin{i+1}; vel = varargin{i+1};
i=i+2; i=i+2;
case 'aux' case 'aux'
auxiliary = varargin{i+1}; auxiliary = varargin{i+1};
auxstatus = 1; auxstatus = 1;
i=i+2; i=i+2;
case 'atomtype' case 'atomtype'
atom_type = varargin{i+1}; atom_type = varargin{i+1};
atom_typestatus = 1; atom_typestatus = 1;
i=i+2; i=i+2;
case 'rotation' case 'rotation'
nrot = varargin{i+1}; % number of rotations nrot = varargin{i+1}; % number of rotations
i = i+2; i = i+2;
if nrot <=0 if nrot <=0
error('Number of rotations must be a positive value'); error('Number of rotations must be a positive value');
end end
rotstatus = 1; rotstatus = 1;
for j = 1 : 1 : nrot for j = 1 : 1 : nrot
rotaxes{j} = varargin{i}; rotaxes{j} = varargin{i};
i = i + 1; i = i + 1;
rotangle(j) = varargin{i}; rotangle(j) = varargin{i};
i = i + 1; i = i + 1;
end end
case 'autonumber' case 'autonumber'
numberstate = varargin{i+1}; numberstate = varargin{i+1};
i = i +2; i = i +2;
if strcmpi(numberstate,'ON') if strcmpi(numberstate,'ON')
autonumber_status = 1; autonumber_status = 1;
elseif strcmpi(numberstate,'OFF') elseif strcmpi(numberstate,'OFF')
autonumber_status = 0; autonumber_status = 0;
end end
case 'autolog' case 'autolog'
logstate = varargin{i+1}; logstate = varargin{i+1};
i = i + 2; i = i + 2;
if strcmpi(logstate,'ON') if strcmpi(logstate,'ON')
autolog_status = 1; autolog_status = 1;
elseif strcmpi(logstate,'OFF') elseif strcmpi(logstate,'OFF')
autolog_status = 0; autolog_status = 0;
end end
end end
end end
end end
% Calculating Transformation matrix [T] % Calculating Transformation matrix [T]
if rotstatus == 0 if rotstatus == 0
T = eye(3); % Identity matrix T = eye(3); % Identity matrix
elseif rotstatus == 1 elseif rotstatus == 1
T = eye(3); T = eye(3);
for j = 1 : 1 : nrot for j = 1 : 1 : nrot
B = beta(rotangle(j)*pi/180,rotaxes{j}); B = beta(rotangle(j)*pi/180,rotaxes{j});
T = B*T; T = B*T;
end end
end end
T = T'; % because Transform = [beta]transpose T = T'; % because Transform = [beta]transpose
%---------------------------------- %----------------------------------
nfiles = length(timestep); nfiles = length(timestep);
%----Default Atom type names------------ %----Default Atom type names------------
if atom_typestatus == 0 if atom_typestatus == 0
atom_type = {'Au' atom_type = {'Au'
'Ni' 'Ni'
'Zn' 'Zn'
'H' 'H'
'O' 'O'
'Cu' 'Cu'
'Al' 'Al'
'Ag' 'Ag'
'C' 'C'
'Si'}; 'Si'};
end end
%--------Sorting atom types --------- %--------Sorting atom types ---------
[s,id] = sort(atom_data(:,2,:)); [s,id] = sort(atom_data(:,2,:));
%---------Writing CFG files--------------- %---------Writing CFG files---------------
for i = 1 : 1 : nfiles for i = 1 : 1 : nfiles
if autonumber_status == 1 if autonumber_status == 1
n = [filename '_' num2str(i) '.cfg']; n = [filename '_' num2str(i) '.cfg'];
elseif autonumber_status == 0 elseif autonumber_status == 0
n = [filename '.cfg']; n = [filename '.cfg'];
end end
name{i}=n; name{i}=n;
fid = fopen(name{i},'w+'); fid = fopen(name{i},'w+');
fprintf(fid,'Number of particles = %d\n',Natoms(i)); fprintf(fid,'Number of particles = %d\n',Natoms(i));
fprintf(fid,'A = 1.0000000000 Angstrom \n'); fprintf(fid,'A = 1.0000000000 Angstrom \n');
% Writing [H] % Writing [H]
fprintf(fid,'H0(1,1) = %f A \n',H(1,1)); fprintf(fid,'H0(1,1) = %f A \n',H(1,1));
fprintf(fid,'H0(1,2) = %f A \n',H(1,2)); fprintf(fid,'H0(1,2) = %f A \n',H(1,2));
fprintf(fid,'H0(1,3) = %f A \n',H(1,3)); fprintf(fid,'H0(1,3) = %f A \n',H(1,3));
fprintf(fid,'H0(2,1) = %f A \n',H(2,1)); fprintf(fid,'H0(2,1) = %f A \n',H(2,1));
fprintf(fid,'H0(2,2) = %f A \n',H(2,2)); fprintf(fid,'H0(2,2) = %f A \n',H(2,2));
fprintf(fid,'H0(2,3) = %f A \n',H(2,3)); fprintf(fid,'H0(2,3) = %f A \n',H(2,3));
fprintf(fid,'H0(3,1) = %f A \n',H(3,1)); fprintf(fid,'H0(3,1) = %f A \n',H(3,1));
fprintf(fid,'H0(3,2) = %f A \n',H(3,2)); fprintf(fid,'H0(3,2) = %f A \n',H(3,2));
fprintf(fid,'H0(3,3) = %f A \n',H(3,3)); fprintf(fid,'H0(3,3) = %f A \n',H(3,3));
% Writing [T] % Writing [T]
fprintf(fid,'Transform(1,1) = %f \n',T(1,1)); fprintf(fid,'Transform(1,1) = %f \n',T(1,1));
fprintf(fid,'Transform(1,2) = %f \n',T(1,2)); fprintf(fid,'Transform(1,2) = %f \n',T(1,2));
fprintf(fid,'Transform(1,3) = %f \n',T(1,3)); fprintf(fid,'Transform(1,3) = %f \n',T(1,3));
fprintf(fid,'Transform(2,1) = %f \n',T(2,1)); fprintf(fid,'Transform(2,1) = %f \n',T(2,1));
fprintf(fid,'Transform(2,2) = %f \n',T(2,2)); fprintf(fid,'Transform(2,2) = %f \n',T(2,2));
fprintf(fid,'Transform(2,3) = %f \n',T(2,3)); fprintf(fid,'Transform(2,3) = %f \n',T(2,3));
fprintf(fid,'Transform(3,1) = %f \n',T(3,1)); fprintf(fid,'Transform(3,1) = %f \n',T(3,1));
fprintf(fid,'Transform(3,2) = %f \n',T(3,2)); fprintf(fid,'Transform(3,2) = %f \n',T(3,2));
fprintf(fid,'Transform(3,3) = %f \n',T(3,3)); fprintf(fid,'Transform(3,3) = %f \n',T(3,3));
if strcmpi(vel,'no') if strcmpi(vel,'no')
fprintf(fid,'.NO_VELOCITY. \n'); fprintf(fid,'.NO_VELOCITY. \n');
end end
fprintf(fid,'entry_count = %d \n',length(atom_data(1,:,i))-2); fprintf(fid,'entry_count = %d \n',length(atom_data(1,:,i))-2);
if auxstatus == 1 if auxstatus == 1
for k = 1 : 1 : length(auxiliary(:,1)) for k = 1 : 1 : length(auxiliary(:,1))
fprintf(fid,'auxiliary[%d] = %s [%s]\n',k-1,auxiliary{k,1},... fprintf(fid,'auxiliary[%d] = %s [%s]\n',k-1,auxiliary{k,1},...
auxiliary{k,2}); auxiliary{k,2});
end end
end end
aid = 1; aid = 1;
atom_change = 1; atom_change = 1;
for j = 1 : 1 : Natoms(i) for j = 1 : 1 : Natoms(i)
if atom_change == 1 if atom_change == 1
fprintf(fid,'%f\n',mass(aid)); fprintf(fid,'%f\n',mass(aid));
fprintf(fid,'%s\n',atom_type{aid}); fprintf(fid,'%s\n',atom_type{aid});
end end
atom_change = 0; atom_change = 0;
fprintf(fid,'%f\t',atom_data(id(j,1,i),3:length(atom_data(1,:,i)),i)); fprintf(fid,'%f\t',atom_data(id(j,1,i),3:length(atom_data(1,:,i)),i));
fprintf(fid,'\n'); fprintf(fid,'\n');
if j ~= Natoms if j ~= Natoms
if atom_data(id(j,1,i),2,i) ~= atom_data(id(j+1,1,i),2,i) if atom_data(id(j,1,i),2,i) ~= atom_data(id(j+1,1,i),2,i)
atom_change = 1; atom_change = 1;
aid = aid+1; aid = aid+1;
end end
end end
end end
fclose(fid); fclose(fid);
end end
if autolog_status == 1 if autolog_status == 1
flog = fopen([filename '_lmp2cfg.log'],'w+'); flog = fopen([filename '_lmp2cfg.log'],'w+');
fprintf(flog,'----------------------------------------------------------\n'); fprintf(flog,'----------------------------------------------------------\n');
fprintf(flog,['LAMMPS DUMP to CFG file conversion :\t' datestr(now) '\n']); fprintf(flog,['LAMMPS DUMP to CFG file conversion :\t' datestr(now) '\n']);
fprintf(flog,'----------------------------------------------------------\n'); fprintf(flog,'----------------------------------------------------------\n');
fprintf(flog,'LAMMPS Dump file : \t %s \n\n',dumpfilename); fprintf(flog,'LAMMPS Dump file : \t %s \n\n',dumpfilename);
for i = 1 : 1 : nfiles for i = 1 : 1 : nfiles
fprintf(flog,'Timestep : %d --> \t\t %s \n',timestep(i),name{i}); fprintf(flog,'Timestep : %d --> \t\t %s \n',timestep(i),name{i});
end end
fclose(flog); fclose(flog);
end end
%---------- Function to calculate beta %---------- Function to calculate beta
function b = beta(angle,axes) function b = beta(angle,axes)
switch axes switch axes
case 'X' % X axes case 'X' % X axes
b = [1 0 0 b = [1 0 0
0 cos(angle) sin(angle) 0 cos(angle) sin(angle)
0 -sin(angle) cos(angle)]; 0 -sin(angle) cos(angle)];
case 'Y' % Y axes case 'Y' % Y axes
b = [cos(angle) 0 sin(angle) b = [cos(angle) 0 sin(angle)
0 1 0 0 1 0
-sin(angle) 0 cos(angle)]; -sin(angle) 0 cos(angle)];
case 'Z' % Z axes case 'Z' % Z axes
b = [cos(angle) sin(angle) 0 b = [cos(angle) sin(angle) 0
-sin(angle) cos(angle) 0 -sin(angle) cos(angle) 0
0 0 1]; 0 0 1];
end end
end end
% -------------------------------------------------- % --------------------------------------------------
end % For main function end % For main function

View File

@ -1,166 +1,166 @@
function varargout = readEAM(varargin) function varargout = readEAM(varargin)
% Function to read EAM potential files % Function to read EAM potential files
% Input % Input
% 1: EAM potential file name % 1: EAM potential file name
% 2: file type --> 'FUNCFL' for single element file % 2: file type --> 'FUNCFL' for single element file
% --> 'SETFL' for multiple element file % --> 'SETFL' for multiple element file
% Output : Structure with members % Output : Structure with members
% .embed : Embedding function % .embed : Embedding function
% .pair : Pair Potential % .pair : Pair Potential
% .elecden : Electron Density % .elecden : Electron Density
% .nrho : Number of points for electron density % .nrho : Number of points for electron density
% .drho : increment of r for electron density % .drho : increment of r for electron density
% .nr : Number of points for pair potential % .nr : Number of points for pair potential
% .dr : increment of r for pair potential % .dr : increment of r for pair potential
% .rcut : cut-off distance % .rcut : cut-off distance
% All output is in exactly the same units as in the EAM file. For % All output is in exactly the same units as in the EAM file. For
% multielement SETFL files the members are multidimensional arrays with % multielement SETFL files the members are multidimensional arrays with
% each element data stored in (:,:,ELEM) % each element data stored in (:,:,ELEM)
% %
% Example % Example
% eam = readEAM('cuu3.eam','funcfl'); % eam = readEAM('cuu3.eam','funcfl');
% %
% Author : Arun K. Subramaniyan % Author : Arun K. Subramaniyan
% sarunkarthi@gmail.com % sarunkarthi@gmail.com
% http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm % http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm
% School of Aeronautics and Astronautics % School of Aeronautics and Astronautics
% Purdue University, West Lafayette, IN - 47907, USA. % Purdue University, West Lafayette, IN - 47907, USA.
if length(varargin) < 2 if length(varargin) < 2
error('Too few input parameters : Need Filename and filetype'); error('Too few input parameters : Need Filename and filetype');
elseif length(varargin) > 2 elseif length(varargin) > 2
error('Too many input parameters'); error('Too many input parameters');
end end
filename = varargin{1}; filename = varargin{1};
type = varargin{2}; type = varargin{2};
try try
fid = fopen(filename,'r'); fid = fopen(filename,'r');
catch catch
error('EAM file not found!'); error('EAM file not found!');
end end
if strcmpi(type,'FUNCFL') if strcmpi(type,'FUNCFL')
t = 1; t = 1;
elseif strcmpi(type,'SETFL') elseif strcmpi(type,'SETFL')
t = 2; t = 2;
else else
error(['Unknown file type : "' type '"']); error(['Unknown file type : "' type '"']);
end end
switch t switch t
case 1 %FUNCFL case 1 %FUNCFL
% Read line 1 : comment line % Read line 1 : comment line
a = fgetl(fid); a = fgetl(fid);
% read Line 2 % read Line 2
rem = fgetl(fid); % ielem amass blat lat rem = fgetl(fid); % ielem amass blat lat
[ielem,rem] = strtok(rem); [ielem,rem] = strtok(rem);
[amass,rem] = strtok(rem); [amass,rem] = strtok(rem);
[blat,rem] = strtok(rem); [blat,rem] = strtok(rem);
[lat,rem] = strtok(rem); [lat,rem] = strtok(rem);
ielem = str2num(ielem); % Atomic Number ielem = str2num(ielem); % Atomic Number
amass = str2num(amass); % Atomic Mass amass = str2num(amass); % Atomic Mass
blat = str2num(blat); % Lattice Constant blat = str2num(blat); % Lattice Constant
% Read Line 3 % Read Line 3
a = str2num(fgetl(fid)); a = str2num(fgetl(fid));
nrho = a(1); nrho = a(1);
drho = a(2); drho = a(2);
nr = a(3); nr = a(3);
dr = a(4); dr = a(4);
rcut = a(5); rcut = a(5);
% Reading embedding function % Reading embedding function
for i = 1 : 1 : nrho/5 for i = 1 : 1 : nrho/5
embed(i,:) = str2num(fgetl(fid)); embed(i,:) = str2num(fgetl(fid));
end end
% Reading pair potential % Reading pair potential
for i = 1 : 1 : nr/5 for i = 1 : 1 : nr/5
pair(i,:) = str2num(fgetl(fid)); pair(i,:) = str2num(fgetl(fid));
end end
% Reading electron density function % Reading electron density function
for i = 1 : 1 : nr/5 for i = 1 : 1 : nr/5
elecden(i,:) = str2num(fgetl(fid)); elecden(i,:) = str2num(fgetl(fid));
end end
% Output % Output
out.embed = embed; out.embed = embed;
out.pair = pair; out.pair = pair;
out.elecden = elecden; out.elecden = elecden;
out.nrho = nrho; out.nrho = nrho;
out.drho = drho; out.drho = drho;
out.nr = nr; out.nr = nr;
out.dr = dr; out.dr = dr;
out.rcut = rcut; out.rcut = rcut;
varargout{1} = out; varargout{1} = out;
% -------------------------------------------------------------------- % --------------------------------------------------------------------
case 2 % SETFL case 2 % SETFL
% Read lines 1 - 3 : comment lines % Read lines 1 - 3 : comment lines
a = fgetl(fid); a = fgetl(fid);
a = fgetl(fid); a = fgetl(fid);
a = fgetl(fid); a = fgetl(fid);
% Atom types % Atom types
ntypes = str2num(fgetl(fid)); ntypes = str2num(fgetl(fid));
% Read Global information % Read Global information
a = str2num(fgetl(fid)); a = str2num(fgetl(fid));
nrho = a(1); nrho = a(1);
drho = a(2); drho = a(2);
nr = a(3); nr = a(3);
dr = a(4); dr = a(4);
rcut = a(5); rcut = a(5);
% Read element specific Data % Read element specific Data
% Embedding function and Electron Density % Embedding function and Electron Density
for elem = 1 : 1 : ntypes for elem = 1 : 1 : ntypes
rem = fgetl(fid); % ielem amass blat lat rem = fgetl(fid); % ielem amass blat lat
[ielem1,rem] = strtok(rem); [ielem1,rem] = strtok(rem);
[amass1,rem] = strtok(rem); [amass1,rem] = strtok(rem);
[blat1,rem] = strtok(rem); [blat1,rem] = strtok(rem);
[lat1,rem] = strtok(rem); [lat1,rem] = strtok(rem);
ielem(elem) = str2num(ielem1); % Atomic Number ielem(elem) = str2num(ielem1); % Atomic Number
amass(elem) = str2num(amass1); % Atomic Mass amass(elem) = str2num(amass1); % Atomic Mass
blat(elem) = str2num(blat1); % Lattice Constant blat(elem) = str2num(blat1); % Lattice Constant
lat(elem,:) = lat1; % Lattice type lat(elem,:) = lat1; % Lattice type
% Reading embedding function % Reading embedding function
for i = 1 : 1 : nrho/5 for i = 1 : 1 : nrho/5
embed(i,:,elem) = str2num(fgetl(fid)); embed(i,:,elem) = str2num(fgetl(fid));
end end
% Reading electron density function % Reading electron density function
for i = 1 : 1 : nr/5 for i = 1 : 1 : nr/5
elecden(i,:,elem) = str2num(fgetl(fid)); elecden(i,:,elem) = str2num(fgetl(fid));
end end
end end
% Pair Potentials % Pair Potentials
n_pair = ntypes + (factorial(ntypes)/2); n_pair = ntypes + (factorial(ntypes)/2);
for np = 1 : 1 : n_pair for np = 1 : 1 : n_pair
for i = 1 : 1 : nr/5 for i = 1 : 1 : nr/5
pair(i,:,np) = str2num(fgetl(fid)); pair(i,:,np) = str2num(fgetl(fid));
end end
end end
% Output % Output
out.embed = embed; out.embed = embed;
out.elecden = elecden; out.elecden = elecden;
out.pair = pair; out.pair = pair;
out.nrho = nrho; out.nrho = nrho;
out.drho = drho; out.drho = drho;
out.nr = nr; out.nr = nr;
out.dr = dr; out.dr = dr;
out.rcut = rcut; out.rcut = rcut;
varargout{1} = out; varargout{1} = out;
end end

View File

@ -1,120 +1,120 @@
function [varargout] = readdump_one(varargin) function [varargout] = readdump_one(varargin)
% Read LAMMPS dump file one timestep at a time % Read LAMMPS dump file one timestep at a time
% Input % Input
% Dump file name with path % Dump file name with path
% Starting file pointer position in dump file % Starting file pointer position in dump file
% Number of columns in the dump file % Number of columns in the dump file
% Output is in the form of a structure with following variables % Output is in the form of a structure with following variables
% .timestep --> Vector containing all time steps % .timestep --> Vector containing all time steps
% .Natoms --> Vector containing number of atoms at each time step % .Natoms --> Vector containing number of atoms at each time step
% .x_bound --> [t,2] array with xlo,xhi at each time step % .x_bound --> [t,2] array with xlo,xhi at each time step
% .y_bound --> [t,2] array with ylo,yhi at each time step % .y_bound --> [t,2] array with ylo,yhi at each time step
% .z_bound --> [t,2] array with zlo,zhi at each time step % .z_bound --> [t,2] array with zlo,zhi at each time step
% .atom_data --> 2 dimensional array with data % .atom_data --> 2 dimensional array with data
% .position --> file pointer for reading next time % .position --> file pointer for reading next time
% %
% Example % Example
% data = readdump_one('dump.LAMMPS',0,5); % data = readdump_one('dump.LAMMPS',0,5);
% Reads the first timestep in the file dump.LAMMPS % Reads the first timestep in the file dump.LAMMPS
% Specify position = -1 if only the last dump step in the % Specify position = -1 if only the last dump step in the
% file is needed % file is needed
% %
% See also readdump, scandump % See also readdump, scandump
% %
% Author : Arun K. Subramaniyan % Author : Arun K. Subramaniyan
% sarunkarthi@gmail.com % sarunkarthi@gmail.com
% http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm % http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm
% School of Aeronautics and Astronautics % School of Aeronautics and Astronautics
% Purdue University, West Lafayette, IN - 47907, USA. % Purdue University, West Lafayette, IN - 47907, USA.
try try
dump = fopen(varargin{1},'r'); dump = fopen(varargin{1},'r');
catch catch
error('Dumpfile not found!'); error('Dumpfile not found!');
end end
position = varargin{2}; % from beg of file position = varargin{2}; % from beg of file
ncol = varargin{3}; %number of columns ncol = varargin{3}; %number of columns
i=1; i=1;
t=0; t=0;
done = 0; done = 0;
last_status = 0; last_status = 0;
if position ~= -1 if position ~= -1
fseek(dump,position,'bof'); fseek(dump,position,'bof');
else else
last_status = 1; last_status = 1;
end end
while done == 0 & last_status == 0 while done == 0 & last_status == 0
id = fgetl(dump); id = fgetl(dump);
switch id switch id
case 'ITEM: TIMESTEP' case 'ITEM: TIMESTEP'
if t == 0 if t == 0
timestep(i) = str2num(fgetl(dump)); timestep(i) = str2num(fgetl(dump));
t=1; t=1;
end end
case 'ITEM: NUMBER OF ATOMS' case 'ITEM: NUMBER OF ATOMS'
Natoms = str2num(fgetl(dump)); Natoms = str2num(fgetl(dump));
case 'ITEM: BOX BOUNDS' case 'ITEM: BOX BOUNDS'
x_bound(1,:) = str2num(fgetl(dump)); x_bound(1,:) = str2num(fgetl(dump));
y_bound(1,:) = str2num(fgetl(dump)); y_bound(1,:) = str2num(fgetl(dump));
z_bound(1,:) = str2num(fgetl(dump)); z_bound(1,:) = str2num(fgetl(dump));
case 'ITEM: ATOMS' case 'ITEM: ATOMS'
atom_data = zeros(Natoms,ncol);%Allocate memory for atom data atom_data = zeros(Natoms,ncol);%Allocate memory for atom data
for j = 1 : 1: Natoms for j = 1 : 1: Natoms
atom_data(j,:) = str2num(fgetl(dump)); atom_data(j,:) = str2num(fgetl(dump));
end end
done = 1; done = 1;
p = ftell(dump); p = ftell(dump);
end end
end end
% Getting only the last step % Getting only the last step
if last_status == 1 if last_status == 1
% First get the position of the beginning of the last step in the % First get the position of the beginning of the last step in the
% dumpfile % dumpfile
while ~feof(dump) while ~feof(dump)
temp = fgetl(dump); temp = fgetl(dump);
if length(temp) == 14 if length(temp) == 14
if strcmpi(temp,'ITEM: TIMESTEP') if strcmpi(temp,'ITEM: TIMESTEP')
p = ftell(dump); % starting position of line next to the header p = ftell(dump); % starting position of line next to the header
end end
end end
end end
fclose(dump); fclose(dump);
dump = fopen(varargin{1},'r'); dump = fopen(varargin{1},'r');
fseek(dump,p,'bof'); fseek(dump,p,'bof');
% getting Timestep % getting Timestep
timestep = str2num(fgetl(dump)); timestep = str2num(fgetl(dump));
while ~feof(dump) while ~feof(dump)
id = fgetl(dump); id = fgetl(dump);
switch id switch id
case 'ITEM: NUMBER OF ATOMS' case 'ITEM: NUMBER OF ATOMS'
Natoms = str2num(fgetl(dump)); Natoms = str2num(fgetl(dump));
case 'ITEM: BOX BOUNDS' case 'ITEM: BOX BOUNDS'
x_bound(1,:) = str2num(fgetl(dump)); x_bound(1,:) = str2num(fgetl(dump));
y_bound(1,:) = str2num(fgetl(dump)); y_bound(1,:) = str2num(fgetl(dump));
z_bound(1,:) = str2num(fgetl(dump)); z_bound(1,:) = str2num(fgetl(dump));
case 'ITEM: ATOMS' case 'ITEM: ATOMS'
atom_data = zeros(Natoms,ncol);%Allocate memory for atom data atom_data = zeros(Natoms,ncol);%Allocate memory for atom data
for j = 1 : 1: Natoms for j = 1 : 1: Natoms
atom_data(j,:) = str2num(fgetl(dump)); atom_data(j,:) = str2num(fgetl(dump));
end end
end end
end end
end end
%----------Outputs------------- %----------Outputs-------------
%OUTPUTS IN SAME VARIABLE STRUCTURE %OUTPUTS IN SAME VARIABLE STRUCTURE
varargout{1}.timestep = timestep; varargout{1}.timestep = timestep;
varargout{1}.Natoms = Natoms; varargout{1}.Natoms = Natoms;
varargout{1}.x_bound = x_bound; varargout{1}.x_bound = x_bound;
varargout{1}.y_bound = y_bound; varargout{1}.y_bound = y_bound;
varargout{1}.z_bound = z_bound; varargout{1}.z_bound = z_bound;
varargout{1}.atom_data = atom_data; varargout{1}.atom_data = atom_data;
varargout{1}.position = p; %gives postion of ITEM: TIMESTEP line varargout{1}.position = p; %gives postion of ITEM: TIMESTEP line
%------------------------------ %------------------------------
fclose(dump); fclose(dump);

View File

@ -1,92 +1,92 @@
function [varargout] = readlog(varargin) function [varargout] = readlog(varargin)
% Read LAMMPS log files % Read LAMMPS log files
% input is log file name with path % input is log file name with path
% output is a structure --> out % output is a structure --> out
% out.Chead --> has heading of columns in each run % out.Chead --> has heading of columns in each run
% out.data --> has the data during each run in the form of string % out.data --> has the data during each run in the form of string
% Type str2num(out.data{i}) to get the numeric array % Type str2num(out.data{i}) to get the numeric array
% %
% Example % Example
% logdata = readlog('log.LAMMPS'); % logdata = readlog('log.LAMMPS');
% %
% Author : sarunkarthi@gmail.com % Author : sarunkarthi@gmail.com
% http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm % http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm
% Arun K. Subramaniyan % Arun K. Subramaniyan
% School of Aeronautics and Astronautics % School of Aeronautics and Astronautics
% Purdue University, West Lafayette, IN - 47907, USA. % Purdue University, West Lafayette, IN - 47907, USA.
logfile = varargin{1}; logfile = varargin{1};
try try
fid = fopen(logfile,'r'); fid = fopen(logfile,'r');
catch catch
error('Log file not found!'); error('Log file not found!');
end end
loop = 1; loop = 1;
while feof(fid) == 0 while feof(fid) == 0
%----------- To get first line of thermo output -------- %----------- To get first line of thermo output --------
while feof(fid) == 0 while feof(fid) == 0
a = fgetl(fid); a = fgetl(fid);
if length(a) > 4 && strcmp(a(1:4),'Step') if length(a) > 4 && strcmp(a(1:4),'Step')
findstep = 1; findstep = 1;
break; break;
end end
end end
%------------------------------------------------------- %-------------------------------------------------------
%---------Seperate column headings---------------------- %---------Seperate column headings----------------------
j=1; j=1;
k=1; k=1;
Ch=''; Ch='';
i=1; i=1;
while i < length(a) && findstep == 1 while i < length(a) && findstep == 1
for i = k : 1 : length(a) for i = k : 1 : length(a)
if strcmp(a(i),' ') if strcmp(a(i),' ')
Chead{loop,j} = Ch; Chead{loop,j} = Ch;
clear Ch; clear Ch;
Ch = ''; Ch = '';
k=i+1; k=i+1;
j=j+1; j=j+1;
break; break;
else else
Ch = [Ch a(i)]; Ch = [Ch a(i)];
end end
end end
end end
if findstep == 1 if findstep == 1
Chead{loop,j} = Ch; % to get the last column heading Chead{loop,j} = Ch; % to get the last column heading
end end
%------------------------------------------------------- %-------------------------------------------------------
%----------------------Get Data------------------------- %----------------------Get Data-------------------------
id = 1; %row id... id = 1; %row id...
while feof(fid) == 0 while feof(fid) == 0
a = fgetl(fid); a = fgetl(fid);
if strcmp(a(1:4),'Loop') if strcmp(a(1:4),'Loop')
loop = loop + 1; loop = loop + 1;
break; break;
else else
logdata(id,:) = str2num(a); logdata(id,:) = str2num(a);
id = id+1; id = id+1;
end end
end end
%-------------------------------------------------------- %--------------------------------------------------------
if feof(fid) == 0 if feof(fid) == 0
b = num2str(logdata); b = num2str(logdata);
data{loop-1} = b; data{loop-1} = b;
clear b; clear b;
clear logdata; clear logdata;
findstep = 0; findstep = 0;
end end
end end
fclose(fid); fclose(fid);
%--------OUTPUT------------------------------------------- %--------OUTPUT-------------------------------------------
out.Chead = Chead; out.Chead = Chead;
out.data = data; out.data = data;
varargout{1} = out; varargout{1} = out;

View File

@ -1,142 +1,142 @@
function varargout = readrdf(varargin) function varargout = readrdf(varargin)
% Function to read Radial Distribution Funtion output from LAMMPS % Function to read Radial Distribution Funtion output from LAMMPS
% Input % Input
% 'bin' --> number of bins in rdf histogram % 'bin' --> number of bins in rdf histogram
% 'runtime' --> Run length of each of the run commands % 'runtime' --> Run length of each of the run commands
% 'step' --> rdf Dump step for each of the run commands % 'step' --> rdf Dump step for each of the run commands
% 'ncol' --> number of columns in the file % 'ncol' --> number of columns in the file
% 'final' --> 'YES' indicates that only the average values will be extracted % 'final' --> 'YES' indicates that only the average values will be extracted
% If only the averages are needed, you don't need to specify 'runtime', % If only the averages are needed, you don't need to specify 'runtime',
% 'step' and 'ncol' % 'step' and 'ncol'
% %
% Output is in the form of a structure with following variables % Output is in the form of a structure with following variables
% %
% if 'final' was given as 'NO' % if 'final' was given as 'NO'
% .rdf_step_data --> Matrix with RDF for each of the dumped steps % .rdf_step_data --> Matrix with RDF for each of the dumped steps
% .rdf_ave_data --> Matrix with average RDF for each RUN % .rdf_ave_data --> Matrix with average RDF for each RUN
% .rdf_ave_data --> Matrix with average RDF for each RUN % .rdf_ave_data --> Matrix with average RDF for each RUN
% %
% if 'final' was given as 'YES' % if 'final' was given as 'YES'
% .rdf_ave_data --> Matrix with average RDF for each RUN % .rdf_ave_data --> Matrix with average RDF for each RUN
% %
% Example % Example
% rdf = readrdf('inputfile','bin',100,'runtime',[30000;20000],... % rdf = readrdf('inputfile','bin',100,'runtime',[30000;20000],...
% 'step',[100;100],'ncol',3,'final','no') % 'step',[100;100],'ncol',3,'final','no')
% %
% Author : Arun K. Subramaniyan % Author : Arun K. Subramaniyan
% sarunkarthi@gmail.com % sarunkarthi@gmail.com
% http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm % http://web.ics.purdue.edu/~asubrama/pages/Research_Main.htm
% School of Aeronautics and Astronautics % School of Aeronautics and Astronautics
% Purdue University, West Lafayette, IN - 47907, USA. % Purdue University, West Lafayette, IN - 47907, USA.
rdf_name = varargin{1}; % RDF File name rdf_name = varargin{1}; % RDF File name
% Setting all status checks to zero % Setting all status checks to zero
bin_status = 0; bin_status = 0;
runtime_status = 0; runtime_status = 0;
step_status = 0; step_status = 0;
ncol_status = 0; ncol_status = 0;
final_status = 'no'; final_status = 'no';
for id = 2 : 1 : length(varargin) for id = 2 : 1 : length(varargin)
if strcmpi(varargin{id},'bin') if strcmpi(varargin{id},'bin')
rdf_bin = varargin{id+1}; % RDF bins rdf_bin = varargin{id+1}; % RDF bins
bin_status = 1; bin_status = 1;
elseif strcmpi(varargin{id},'runtime') elseif strcmpi(varargin{id},'runtime')
rdf_runtime = varargin{id+1}; % Runtimes rdf_runtime = varargin{id+1}; % Runtimes
runtime_status = 1; runtime_status = 1;
elseif strcmpi(varargin{id},'step') elseif strcmpi(varargin{id},'step')
rdf_step = varargin{id+1}; % Runtimes rdf_step = varargin{id+1}; % Runtimes
step_status = 1; step_status = 1;
elseif strcmpi(varargin{id},'ncol') elseif strcmpi(varargin{id},'ncol')
ncol = varargin{id+1}; % Runtimes ncol = varargin{id+1}; % Runtimes
ncol_status = 1; ncol_status = 1;
elseif strcmpi(varargin{id},'final') elseif strcmpi(varargin{id},'final')
final_status = varargin{id+1}; final_status = varargin{id+1};
end end
end end
if ncol_status == 0 if ncol_status == 0
ncol = 3; ncol = 3;
end end
% Check for errors in input arguments % Check for errors in input arguments
if bin_status == 0 if bin_status == 0
error('No bin specified'); error('No bin specified');
elseif step_status == 1 && runtime_status == 0 elseif step_status == 1 && runtime_status == 0
error('Step size specified without Runtime'); error('Step size specified without Runtime');
elseif step_status == 0 && runtime_status == 1 elseif step_status == 0 && runtime_status == 1
error('Runtime specified without Step size'); error('Runtime specified without Step size');
end end
if step_status == 1 && runtime_status == 1 if step_status == 1 && runtime_status == 1
if length(rdf_runtime) ~= length(rdf_step) if length(rdf_runtime) ~= length(rdf_step)
error('Runtime and Step size do not match'); error('Runtime and Step size do not match');
end end
end end
% Preallocating memory if runtime and step size are provided % Preallocating memory if runtime and step size are provided
if step_status == 1 && runtime_status == 1 && strcmpi(final_status,'no') if step_status == 1 && runtime_status == 1 && strcmpi(final_status,'no')
total_steps = round(sum(rdf_runtime./rdf_step)); total_steps = round(sum(rdf_runtime./rdf_step));
rdf_step_data = zeros(rdf_bin,ncol,total_steps); rdf_step_data = zeros(rdf_bin,ncol,total_steps);
rdf_ave_data = zeros(rdf_bin,ncol,length(rdf_runtime)); rdf_ave_data = zeros(rdf_bin,ncol,length(rdf_runtime));
elseif strcmpi(final_status,'yes') && step_status == 1 && runtime_status == 1 elseif strcmpi(final_status,'yes') && step_status == 1 && runtime_status == 1
rdf_ave_data = zeros(rdf_bin,ncol,length(rdf_runtime)); rdf_ave_data = zeros(rdf_bin,ncol,length(rdf_runtime));
end end
try try
rdf_file = fopen(rdf_name,'r'); rdf_file = fopen(rdf_name,'r');
catch catch
error('RDF file not found!'); error('RDF file not found!');
end end
if strcmpi(final_status,'yes') if strcmpi(final_status,'yes')
run_id = 1; % Run id.. run_id = 1; % Run id..
while feof(rdf_file) ~= 1 while feof(rdf_file) ~= 1
rdf_data = fgetl(rdf_file); rdf_data = fgetl(rdf_file);
if strcmpi(rdf_data(1:11),'RUN AVERAGE') if strcmpi(rdf_data(1:11),'RUN AVERAGE')
fgetl(rdf_file); % to skip the title fgetl(rdf_file); % to skip the title
for id = 1 : 1 : rdf_bin for id = 1 : 1 : rdf_bin
rdf_ave_data(id,:,run_id) = str2num(fgetl(rdf_file)); rdf_ave_data(id,:,run_id) = str2num(fgetl(rdf_file));
end end
run_id = run_id + 1; run_id = run_id + 1;
end end
end end
else else
run_id = 1; run_id = 1;
id = 1; id = 1;
while feof(rdf_file) ~= 1 while feof(rdf_file) ~= 1
rdf_data = fgetl(rdf_file); rdf_data = fgetl(rdf_file);
if strcmpi(rdf_data(1:8),'TIMESTEP') if strcmpi(rdf_data(1:8),'TIMESTEP')
timestep(id,1) = str2num(rdf_data(10:length(rdf_data))); timestep(id,1) = str2num(rdf_data(10:length(rdf_data)));
fgetl(rdf_file); % to skip the title fgetl(rdf_file); % to skip the title
for j = 1 : 1 : rdf_bin for j = 1 : 1 : rdf_bin
rdf_step_data(j,:,id) = str2num(fgetl(rdf_file)); rdf_step_data(j,:,id) = str2num(fgetl(rdf_file));
end end
id = id+1; id = id+1;
elseif strcmpi(rdf_data(1:11),'RUN AVERAGE') elseif strcmpi(rdf_data(1:11),'RUN AVERAGE')
fgetl(rdf_file); % to skip the title fgetl(rdf_file); % to skip the title
for j = 1 : 1 : rdf_bin for j = 1 : 1 : rdf_bin
rdf_ave_data(j,:,run_id) = str2num(fgetl(rdf_file)); rdf_ave_data(j,:,run_id) = str2num(fgetl(rdf_file));
end end
run_id = run_id + 1; run_id = run_id + 1;
end end
end end
end end
fclose(rdf_file); fclose(rdf_file);
if strcmpi(final_status,'no') if strcmpi(final_status,'no')
out_data.timestep = timestep; out_data.timestep = timestep;
out_data.rdf_step_data = rdf_step_data; out_data.rdf_step_data = rdf_step_data;
out_data.rdf_ave_data = rdf_ave_data; out_data.rdf_ave_data = rdf_ave_data;
else else
out_data.rdf_ave_data = rdf_ave_data; out_data.rdf_ave_data = rdf_ave_data;
end end
varargout{1} = out_data; varargout{1} = out_data;

View File

@ -261,7 +261,7 @@ void GetParameters(int Forcefield)
for (j=0; j < 3; j++) for (j=0; j < 3; j++)
fprintf(stderr," %-3s", atomtypes[angletypes[i].types[j]].potential); fprintf(stderr," %-3s", atomtypes[angletypes[i].types[j]].potential);
for (j=0; j < 4; j++) fprintf(stderr," %8.4f",angletypes[i].params[j]); for (j=0; j < 4; j++) fprintf(stderr," %8.4f",angletypes[i].params[j]);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
if (forcefield > 1) { if (forcefield > 1) {
@ -448,7 +448,7 @@ void GetParameters(int Forcefield)
} }
else { else {
dihedraltypes[i].midbonddihedral_cross_term[0] = dihedraltypes[i].midbonddihedral_cross_term[0] =
ff_midbontor.data[k].ff_param[0]; ff_midbontor.data[k].ff_param[0];
dihedraltypes[i].midbonddihedral_cross_term[1] = dihedraltypes[i].midbonddihedral_cross_term[1] =
ff_midbontor.data[k].ff_param[1]; ff_midbontor.data[k].ff_param[1];
dihedraltypes[i].midbonddihedral_cross_term[2] = dihedraltypes[i].midbonddihedral_cross_term[2] =
@ -482,7 +482,7 @@ void GetParameters(int Forcefield)
} }
else { else {
dihedraltypes[i].angledihedral_cross_term[0] = dihedraltypes[i].angledihedral_cross_term[0] =
ff_angtor.data[k].ff_param[0]; ff_angtor.data[k].ff_param[0];
dihedraltypes[i].angledihedral_cross_term[1] = dihedraltypes[i].angledihedral_cross_term[1] =
ff_angtor.data[k].ff_param[1]; ff_angtor.data[k].ff_param[1];
dihedraltypes[i].angledihedral_cross_term[2] = dihedraltypes[i].angledihedral_cross_term[2] =

View File

@ -33,7 +33,7 @@ void InitializeItems(void)
} }
else { else {
strcpy(ff_bond.keyword, "#quartic_bond"); strcpy(ff_bond.keyword, "#quartic_bond");
ff_bond.number_of_parameters = 4; ff_bond.number_of_parameters = 4;
} }
/* ANGLE */ /* ANGLE */

File diff suppressed because it is too large Load Diff

View File

@ -1,171 +1,171 @@
/* /*
* This function opens the .car file and extracts coordinate information * This function opens the .car file and extracts coordinate information
* into the atoms Atom structure * into the atoms Atom structure
*/ */
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
void ReadCarFile(void) void ReadCarFile(void)
{ {
char line[MAX_LINE_LENGTH]; /* Stores lines as they are read in */ char line[MAX_LINE_LENGTH]; /* Stores lines as they are read in */
int k,m,n; /* counters */ int k,m,n; /* counters */
int skip; /* lines to skip at beginning of file */ int skip; /* lines to skip at beginning of file */
double lowest, highest; /* temp coordinate finding variables */ double lowest, highest; /* temp coordinate finding variables */
double total_q; double total_q;
/* Open .car file for reading */ /* Open .car file for reading */
sprintf(line,"%s.car",rootname); sprintf(line,"%s.car",rootname);
if (pflag > 0) fprintf(stderr," Reading car file: %s\n",line); if (pflag > 0) fprintf(stderr," Reading car file: %s\n",line);
if( (CarF = fopen(line,"r")) == NULL ) { if( (CarF = fopen(line,"r")) == NULL ) {
fprintf(stderr,"Cannot open %s\n",line); fprintf(stderr,"Cannot open %s\n",line);
exit(2); exit(2);
} }
/* Determine Number of molecules & atoms */ /* Determine Number of molecules & atoms */
rewind(CarF); rewind(CarF);
no_molecules = -1; /* Set to -1 because counter will be incremented an no_molecules = -1; /* Set to -1 because counter will be incremented an
extra time at the end of the file */ extra time at the end of the file */
fgets(line,MAX_LINE_LENGTH,CarF); /* Read header line */ fgets(line,MAX_LINE_LENGTH,CarF); /* Read header line */
/* Check for periodicity, if present, read cell constants */ /* Check for periodicity, if present, read cell constants */
if( strncmp(fgets(line,MAX_LINE_LENGTH,CarF),"PBC=ON",6) == 0) { if( strncmp(fgets(line,MAX_LINE_LENGTH,CarF),"PBC=ON",6) == 0) {
periodic = 1; periodic = 1;
skip = 5; /* Data starts 5 lines from beginning of file */ skip = 5; /* Data starts 5 lines from beginning of file */
fgets(line,MAX_LINE_LENGTH,CarF); /* Comment line */ fgets(line,MAX_LINE_LENGTH,CarF); /* Comment line */
fgets(line,MAX_LINE_LENGTH,CarF); /* Date stamp */ fgets(line,MAX_LINE_LENGTH,CarF); /* Date stamp */
fscanf(CarF,"%*s %lf %lf %lf %lf %lf %lf %*s", fscanf(CarF,"%*s %lf %lf %lf %lf %lf %lf %*s",
&pbc[0],&pbc[1],&pbc[2],&pbc[3],&pbc[4],&pbc[5]); &pbc[0],&pbc[1],&pbc[2],&pbc[3],&pbc[4],&pbc[5]);
if(pbc[3] != 90.0 || pbc[4] != 90.0 || pbc[5] != 90.0) { if(pbc[3] != 90.0 || pbc[4] != 90.0 || pbc[5] != 90.0) {
fprintf(stderr,"The system is not rectangular- LAMMPS can't handle it!!"); fprintf(stderr,"The system is not rectangular- LAMMPS can't handle it!!");
exit(2); exit(2);
} }
} }
else { else {
periodic = 0; periodic = 0;
skip = 4; skip = 4;
if (pflag > 1) { if (pflag > 1) {
fprintf(stderr," %s is not a periodic system\n", rootname); fprintf(stderr," %s is not a periodic system\n", rootname);
fprintf(stderr," Assigning cell parameters based on coordinates\n"); fprintf(stderr," Assigning cell parameters based on coordinates\n");
} }
fgets(line,MAX_LINE_LENGTH, CarF); /* Comment line */ fgets(line,MAX_LINE_LENGTH, CarF); /* Comment line */
fgets(line,MAX_LINE_LENGTH, CarF); /* Date Stamp */ fgets(line,MAX_LINE_LENGTH, CarF); /* Date Stamp */
} }
/* First pass through file -- Count molecules */ /* First pass through file -- Count molecules */
while(fgets(line,MAX_LINE_LENGTH,CarF) != NULL ) while(fgets(line,MAX_LINE_LENGTH,CarF) != NULL )
if( strncmp(line,"end",3) == 0 ) if( strncmp(line,"end",3) == 0 )
no_molecules++; no_molecules++;
/* Allocate space to keep track of the number of atoms within a molecule */ /* Allocate space to keep track of the number of atoms within a molecule */
no_atoms = (int *) calloc(no_molecules,sizeof(int)); no_atoms = (int *) calloc(no_molecules,sizeof(int));
if ( no_atoms == NULL ) { if ( no_atoms == NULL ) {
fprintf(stderr,"Could not allocate memory for no_atoms\n"); fprintf(stderr,"Could not allocate memory for no_atoms\n");
exit(2); exit(2);
} }
/* Second pass through file -- Count atoms */ /* Second pass through file -- Count atoms */
rewind(CarF); rewind(CarF);
for(n=0; n < skip; n++) /* Skip beginning lines */ for(n=0; n < skip; n++) /* Skip beginning lines */
fgets(line,MAX_LINE_LENGTH,CarF); fgets(line,MAX_LINE_LENGTH,CarF);
for(n=0; n < no_molecules; n++) for(n=0; n < no_molecules; n++)
while( strncmp(fgets(line,MAX_LINE_LENGTH,CarF),"end",3) ) while( strncmp(fgets(line,MAX_LINE_LENGTH,CarF),"end",3) )
no_atoms[n]++; no_atoms[n]++;
for( total_no_atoms=0, n=0; n < no_molecules; n++ ) for( total_no_atoms=0, n=0; n < no_molecules; n++ )
total_no_atoms += no_atoms[n]; total_no_atoms += no_atoms[n];
molecule = (struct MoleculeList *) calloc(no_molecules, molecule = (struct MoleculeList *) calloc(no_molecules,
sizeof(struct MoleculeList)); sizeof(struct MoleculeList));
if (molecule == NULL) { if (molecule == NULL) {
fprintf(stderr,"Unable to allocate memory for molecule structure\n"); fprintf(stderr,"Unable to allocate memory for molecule structure\n");
exit(2); exit(2);
} }
molecule[0].start = 0; molecule[0].start = 0;
molecule[0].end = no_atoms[0]; molecule[0].end = no_atoms[0];
for (n=1; n < no_molecules; n++) { for (n=1; n < no_molecules; n++) {
molecule[n].start = molecule[n-1].end; molecule[n].start = molecule[n-1].end;
molecule[n].end = molecule[n].start + no_atoms[n]; molecule[n].end = molecule[n].start + no_atoms[n];
} }
/* Allocate space for atoms Atom structures */ /* Allocate space for atoms Atom structures */
atoms = (struct Atom *) calloc(total_no_atoms,sizeof(struct Atom)); atoms = (struct Atom *) calloc(total_no_atoms,sizeof(struct Atom));
if( atoms == NULL ) { if( atoms == NULL ) {
fprintf(stderr,"Could not allocate memory for AtomList\n"); fprintf(stderr,"Could not allocate memory for AtomList\n");
exit(2); exit(2);
} }
/* Third pass through file -- Read+Parse Car File */ /* Third pass through file -- Read+Parse Car File */
rewind(CarF); rewind(CarF);
for(n=0; n < skip; n++) for(n=0; n < skip; n++)
fgets(line,MAX_LINE_LENGTH,CarF); fgets(line,MAX_LINE_LENGTH,CarF);
for(m=0; m < no_molecules; m++) { for(m=0; m < no_molecules; m++) {
for(k=molecule[m].start; k < for(k=molecule[m].start; k <
molecule[m].end; k++) { molecule[m].end; k++) {
atoms[k].molecule = m; atoms[k].molecule = m;
atoms[k].no = k; atoms[k].no = k;
fscanf(CarF,"%s %lf %lf %lf %*s %*s %s %s %f", fscanf(CarF,"%s %lf %lf %lf %*s %*s %s %s %f",
atoms[k].name, atoms[k].name,
&(atoms[k].x[0]), &(atoms[k].x[0]),
&(atoms[k].x[1]), &(atoms[k].x[1]),
&(atoms[k].x[2]), &(atoms[k].x[2]),
atoms[k].potential, atoms[k].potential,
atoms[k].element, atoms[k].element,
&(atoms[k].q)); &(atoms[k].q));
} }
fgets(line,MAX_LINE_LENGTH,CarF); fgets(line,MAX_LINE_LENGTH,CarF);
fgets(line,MAX_LINE_LENGTH,CarF); fgets(line,MAX_LINE_LENGTH,CarF);
} /* End m (molecule) loop */ } /* End m (molecule) loop */
for (total_q=0.0,k=0; k < total_no_atoms; k++) for (total_q=0.0,k=0; k < total_no_atoms; k++)
total_q += atoms[k].q; total_q += atoms[k].q;
if (pflag > 1) { if (pflag > 1) {
fprintf(stderr," There are %d atoms in %d molecules in this file\n", fprintf(stderr," There are %d atoms in %d molecules in this file\n",
total_no_atoms,no_molecules); total_no_atoms,no_molecules);
fprintf(stderr," The total charge in the system is %7.3f.\n\n",total_q); fprintf(stderr," The total charge in the system is %7.3f.\n\n",total_q);
} }
/* Search coordinates to find lowest and highest for x, y, and z */ /* Search coordinates to find lowest and highest for x, y, and z */
if (periodic == 0) { if (periodic == 0) {
for ( k = 0; k < 3; k++) { for ( k = 0; k < 3; k++) {
lowest = atoms[0].x[k]; lowest = atoms[0].x[k];
highest = atoms[0].x[k]; highest = atoms[0].x[k];
for ( m = 1; m < total_no_atoms; m++) { for ( m = 1; m < total_no_atoms; m++) {
if (atoms[m].x[k] < lowest) lowest = atoms[m].x[k]; if (atoms[m].x[k] < lowest) lowest = atoms[m].x[k];
if (atoms[m].x[k] > highest) highest = atoms[m].x[k]; if (atoms[m].x[k] > highest) highest = atoms[m].x[k];
} }
pbc[k] = lowest; pbc[k] = lowest;
pbc[k+3] = highest; pbc[k+3] = highest;
} }
} }
else { else {
for (k=0; k < 3; k++) { for (k=0; k < 3; k++) {
pbc[k+3] = pbc[k]; pbc[k+3] = pbc[k];
pbc[k] = 0.0; pbc[k] = 0.0;
} }
} }
/* Close .car file */ /* Close .car file */
if (fclose(CarF) !=0) { if (fclose(CarF) !=0) {
fprintf(stderr,"Error closing %s.car\n", rootname); fprintf(stderr,"Error closing %s.car\n", rootname);
exit(1); exit(1);
} }
} }
/* End ReadCarFile() */ /* End ReadCarFile() */

View File

@ -1,425 +1,425 @@
/****************************** /******************************
* *
* This function opens the .mdf file and extracts connectivity information * This function opens the .mdf file and extracts connectivity information
* into the atoms Atom structure. It also updates the charge from the .car * into the atoms Atom structure. It also updates the charge from the .car
* file because the charge in the .mdf file has more significant figures. * file because the charge in the .mdf file has more significant figures.
* *
*/ */
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
/* Prototype for function to process a single atom /* Prototype for function to process a single atom
Returns int that flags end of data file */ Returns int that flags end of data file */
int get_molecule(char line[], int connect_col_no, int get_molecule(char line[], int connect_col_no,
int q_col_no, int *counter); int q_col_no, int *counter);
/* Prototype for function that takes connectivty record as stated in /* Prototype for function that takes connectivty record as stated in
.mdf file and fills in any default values */ .mdf file and fills in any default values */
void MakeConnectFullForm(int *counter); void MakeConnectFullForm(int *counter);
/* prototype for function to clean strange characters out of strings */ /* prototype for function to clean strange characters out of strings */
void clean_string(char *); void clean_string(char *);
void ReadMdfFile(void) void ReadMdfFile(void)
{ {
char line[MAX_LINE_LENGTH]; /* Temporary storage for reading lines */ char line[MAX_LINE_LENGTH]; /* Temporary storage for reading lines */
char *col_no; /* Pointer to column number stored as char */ char *col_no; /* Pointer to column number stored as char */
char *col_name; /* Pointer to column name */ char *col_name; /* Pointer to column name */
int connect_col_no = 0; /* Column number where connection info begins */ int connect_col_no = 0; /* Column number where connection info begins */
int q_col_no = 0; /* Column number containg charge information */ int q_col_no = 0; /* Column number containg charge information */
int column_flag=0; /* Flag for finding connect and q col no */ int column_flag=0; /* Flag for finding connect and q col no */
int atom_counter=0; /* Keeps track of current atom number */ int atom_counter=0; /* Keeps track of current atom number */
int p_flag = 1; /* return value from ProcessConnections() */ int p_flag = 1; /* return value from ProcessConnections() */
int i,j,k,kk,l,n,match,match2,status; int i,j,k,kk,l,n,match,match2,status;
char *temp_string; char *temp_string;
char *temp_residue; char *temp_residue;
char *temp_atom_name; char *temp_atom_name;
char *sptr; char *sptr;
char *molecule_name; char *molecule_name;
unsigned char at_end = 0; unsigned char at_end = 0;
/* Open .mdf file for reading */ /* Open .mdf file for reading */
sprintf(line,"%s.mdf",rootname); sprintf(line,"%s.mdf",rootname);
if (pflag > 0) fprintf(stderr," Reading mdf file: %s\n",line); if (pflag > 0) fprintf(stderr," Reading mdf file: %s\n",line);
if ((MdfF = fopen(line,"r")) == NULL ) { if ((MdfF = fopen(line,"r")) == NULL ) {
fprintf(stderr,"Cannot open %s\n",line); fprintf(stderr,"Cannot open %s\n",line);
exit(2); exit(2);
} }
while (!at_end) { while (!at_end) {
sptr = fgets(line,MAX_LINE_LENGTH,MdfF); sptr = fgets(line,MAX_LINE_LENGTH,MdfF);
if (sptr != NULL) { if (sptr != NULL) {
clean_string(line); clean_string(line);
if (strncmp(line,"#end",4) == 0) { if (strncmp(line,"#end",4) == 0) {
at_end = 1; at_end = 1;
} }
else if (strncmp(line,"@column",7) == 0) { else if (strncmp(line,"@column",7) == 0) {
temp_string = strtok(line," "); temp_string = strtok(line," ");
col_no = strtok(NULL," "); col_no = strtok(NULL," ");
col_name = strtok(NULL," "); col_name = strtok(NULL," ");
if (strncmp(col_name,"charge",6) == 0) { if (strncmp(col_name,"charge",6) == 0) {
if (strlen(col_name) < 8) { if (strlen(col_name) < 8) {
q_col_no = atoi(col_no); q_col_no = atoi(col_no);
} }
} }
else if (strncmp(col_name,"connect",7) == 0) { else if (strncmp(col_name,"connect",7) == 0) {
connect_col_no = atoi(col_no); connect_col_no = atoi(col_no);
} }
} }
else if (strncmp(line,"@molecule",9) == 0) { else if (strncmp(line,"@molecule",9) == 0) {
temp_string = strtok(line," "); temp_string = strtok(line," ");
molecule_name = strtok(NULL," "); molecule_name = strtok(NULL," ");
if ((q_col_no == 0) | (connect_col_no == 0)) { if ((q_col_no == 0) | (connect_col_no == 0)) {
fprintf(stderr,"Unable to process molecule without knowing charge\n"); fprintf(stderr,"Unable to process molecule without knowing charge\n");
fprintf(stderr,"and connections columns\n"); fprintf(stderr,"and connections columns\n");
} }
sptr = fgets(line,MAX_LINE_LENGTH,MdfF); sptr = fgets(line,MAX_LINE_LENGTH,MdfF);
status = get_molecule(line,connect_col_no,q_col_no,&atom_counter); status = get_molecule(line,connect_col_no,q_col_no,&atom_counter);
if (status == 0) { if (status == 0) {
fprintf(stderr,"Trouble reading molecule - exiting\n"); fprintf(stderr,"Trouble reading molecule - exiting\n");
} }
} }
else { else {
} }
} }
else { else {
fprintf(stderr,"End of File found or error reading line\n"); fprintf(stderr,"End of File found or error reading line\n");
at_end = 1; at_end = 1;
} }
} }
/* Next build list of residues for each molecule This will /* Next build list of residues for each molecule This will
facilitate assigning connections numbers as well as figuring facilitate assigning connections numbers as well as figuring
out bonds, angles, etc. This first loop just figures out the out bonds, angles, etc. This first loop just figures out the
number of residues in each molecule and allocates memory to number of residues in each molecule and allocates memory to
store information for each residue. The second loop fills store information for each residue. The second loop fills
in starting and ending atom positions for each residue in starting and ending atom positions for each residue
*/ */
temp_string = calloc(16,sizeof(char)); temp_string = calloc(16,sizeof(char));
temp_string[15] = '\0'; temp_string[15] = '\0';
for (n=0; n < no_molecules; n++) { for (n=0; n < no_molecules; n++) {
molecule[n].no_residues = 1; molecule[n].no_residues = 1;
strncpy(temp_string,atoms[molecule[n].start].residue_string,16); strncpy(temp_string,atoms[molecule[n].start].residue_string,16);
for (i=molecule[n].start+1; i < molecule[n].end; i++) { for (i=molecule[n].start+1; i < molecule[n].end; i++) {
if (strncmp(temp_string,atoms[i].residue_string,16) != 0) { if (strncmp(temp_string,atoms[i].residue_string,16) != 0) {
molecule[n].no_residues++; molecule[n].no_residues++;
strncpy(temp_string,atoms[i].residue_string,16); strncpy(temp_string,atoms[i].residue_string,16);
} }
} }
molecule[n].residue = (struct ResidueList *) molecule[n].residue = (struct ResidueList *)
calloc(molecule[n].no_residues, sizeof(struct ResidueList)); calloc(molecule[n].no_residues, sizeof(struct ResidueList));
if (molecule[n].residue == NULL) { if (molecule[n].residue == NULL) {
fprintf(stderr,"Unable to allocate memory for residue list - molecule %d\n", fprintf(stderr,"Unable to allocate memory for residue list - molecule %d\n",
n); n);
exit(1); exit(1);
} }
} }
for (n=0; n < no_molecules; n++) { for (n=0; n < no_molecules; n++) {
j = 0; j = 0;
strncpy(molecule[n].residue[j].name, strncpy(molecule[n].residue[j].name,
atoms[molecule[n].start].residue_string,16); atoms[molecule[n].start].residue_string,16);
molecule[n].residue[j].start = molecule[n].start; molecule[n].residue[j].start = molecule[n].start;
for (i=molecule[n].start+1; i < molecule[n].end; i++) { for (i=molecule[n].start+1; i < molecule[n].end; i++) {
if (strncmp(molecule[n].residue[j].name, if (strncmp(molecule[n].residue[j].name,
atoms[i].residue_string,16) != 0) { atoms[i].residue_string,16) != 0) {
molecule[n].residue[j].end = i; molecule[n].residue[j].end = i;
molecule[n].residue[++j].start = i; molecule[n].residue[++j].start = i;
strncpy(molecule[n].residue[j].name,atoms[i].residue_string,16); strncpy(molecule[n].residue[j].name,atoms[i].residue_string,16);
} }
} }
molecule[n].residue[j].end = molecule[n].end; molecule[n].residue[j].end = molecule[n].end;
/* /*
fprintf(stderr,"Molecule %d has %d residues",n,molecule[n].no_residues); fprintf(stderr,"Molecule %d has %d residues",n,molecule[n].no_residues);
for (i=0; i < molecule[n].no_residues; i++) { for (i=0; i < molecule[n].no_residues; i++) {
fprintf(stderr," %s",molecule[n].residue[i].name); fprintf(stderr," %s",molecule[n].residue[i].name);
} }
fprintf(stderr,"\n"); fprintf(stderr,"\n");
for (i=molecule[n].start; i < molecule[n].end; i++) { for (i=molecule[n].start; i < molecule[n].end; i++) {
fprintf(stderr," atom %d residue %s\n",i,atoms[i].residue_string); fprintf(stderr," atom %d residue %s\n",i,atoms[i].residue_string);
} }
fprintf(stderr," residue %s start %d end %d\n",molecule[n].residue[i].name, fprintf(stderr," residue %s start %d end %d\n",molecule[n].residue[i].name,
molecule[n].residue[i].start,molecule[n].residue[i].end); molecule[n].residue[i].start,molecule[n].residue[i].end);
} }
*/ */
} }
/* Assign atom names in connections[] to corresponding atom numbers */ /* Assign atom names in connections[] to corresponding atom numbers */
for (n=0; n < no_molecules; n++) { for (n=0; n < no_molecules; n++) {
for (j=0; j < molecule[n].no_residues; j++) { for (j=0; j < molecule[n].no_residues; j++) {
for (i=molecule[n].residue[j].start; i < molecule[n].residue[j].end; for (i=molecule[n].residue[j].start; i < molecule[n].residue[j].end;
i++) { i++) {
for (l=0; l < atoms[i].no_connect; l++) { for (l=0; l < atoms[i].no_connect; l++) {
strncpy(temp_string,atoms[i].connections[l],16); strncpy(temp_string,atoms[i].connections[l],16);
temp_residue = strtok(temp_string,":"); temp_residue = strtok(temp_string,":");
temp_atom_name = strtok(NULL,"%"); temp_atom_name = strtok(NULL,"%");
if (strcmp(temp_residue,molecule[n].residue[j].name) == 0) { if (strcmp(temp_residue,molecule[n].residue[j].name) == 0) {
/* atom and connection are part of same residue /* atom and connection are part of same residue
Search names on just that residue */ Search names on just that residue */
k = molecule[n].residue[j].start; k = molecule[n].residue[j].start;
match = 0; match = 0;
while (!match && (k < molecule[n].residue[j].end)) { while (!match && (k < molecule[n].residue[j].end)) {
if (strcmp(atoms[k].name,temp_atom_name) == 0) { if (strcmp(atoms[k].name,temp_atom_name) == 0) {
atoms[i].conn_no[l] = k; atoms[i].conn_no[l] = k;
match = 1; match = 1;
} }
else else
k++; k++;
} }
if (match == 0) { if (match == 0) {
fprintf(stderr,"Unable to resolve atom number of atom %d conn %d string %s:%s\n Something is wrong in the MDF file\n", fprintf(stderr,"Unable to resolve atom number of atom %d conn %d string %s:%s\n Something is wrong in the MDF file\n",
i,l,temp_residue,temp_atom_name); i,l,temp_residue,temp_atom_name);
exit(1); exit(1);
} }
} }
else { else {
/* atom and connection are on different residues /* atom and connection are on different residues
First find the residue that the connection is First find the residue that the connection is
on then loop over its atoms on then loop over its atoms
*/ */
k=0; k=0;
match = 0; match = 0;
while (!match && (k < molecule[n].no_residues)) { while (!match && (k < molecule[n].no_residues)) {
if (strcmp(temp_residue,molecule[n].residue[k].name) == 0) { if (strcmp(temp_residue,molecule[n].residue[k].name) == 0) {
kk = molecule[n].residue[k].start; kk = molecule[n].residue[k].start;
match2 = 0; match2 = 0;
while (!match2 && (kk < molecule[n].residue[k].end)) { while (!match2 && (kk < molecule[n].residue[k].end)) {
if (strcmp(atoms[kk].name,temp_atom_name) == 0) { if (strcmp(atoms[kk].name,temp_atom_name) == 0) {
atoms[i].conn_no[l] = kk; atoms[i].conn_no[l] = kk;
match2 = 1; match2 = 1;
} }
else else
kk++; kk++;
} }
if (match2 == 0) { if (match2 == 0) {
fprintf(stderr,"Unable to resolve atom number of atom %d conn %d string %s\n Something is wrong in the MDF file\n", fprintf(stderr,"Unable to resolve atom number of atom %d conn %d string %s\n Something is wrong in the MDF file\n",
i,l,atoms[i].connections[l]); i,l,atoms[i].connections[l]);
exit(1); exit(1);
} }
match = 1; match = 1;
} }
else else
k++; k++;
} }
if (match == 0) { if (match == 0) {
fprintf(stderr,"Unable to find residue associated with conn %d %s on atom %d\n Something is wrong in the MDF file\n", l,atoms[i].connections[l],i); fprintf(stderr,"Unable to find residue associated with conn %d %s on atom %d\n Something is wrong in the MDF file\n", l,atoms[i].connections[l],i);
exit(1); exit(1);
} }
} /* end if */ } /* end if */
} /* l - loop over connections on atom i */ } /* l - loop over connections on atom i */
} /* i - loop on atoms in residue j molecule n */ } /* i - loop on atoms in residue j molecule n */
} /* j - loop on residues in molecule n */ } /* j - loop on residues in molecule n */
} /* n - loop over molecules */ } /* n - loop over molecules */
free(temp_string); free(temp_string);
/* /*
for (n=0; n < no_molecules; n++) { for (n=0; n < no_molecules; n++) {
fprintf(stderr,"Molecule %d has %d residues\n",n,molecule[n].no_residues); fprintf(stderr,"Molecule %d has %d residues\n",n,molecule[n].no_residues);
for (j=0; j < molecule[n].no_residues; j++) { for (j=0; j < molecule[n].no_residues; j++) {
fprintf(stderr," Residue %d named %s\n",j,molecule[n].residue[j].name); fprintf(stderr," Residue %d named %s\n",j,molecule[n].residue[j].name);
for (i=molecule[n].residue[j].start; i < molecule[n].residue[j].end; for (i=molecule[n].residue[j].start; i < molecule[n].residue[j].end;
i++) { i++) {
fprintf(stderr," Atom %d type %s connected to ",i,atoms[i].potential); fprintf(stderr," Atom %d type %s connected to ",i,atoms[i].potential);
for (l=0; l < atoms[i].no_connect; l++) fprintf(stderr," %d ", for (l=0; l < atoms[i].no_connect; l++) fprintf(stderr," %d ",
atoms[i].conn_no[l]); atoms[i].conn_no[l]);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
} }
} }
*/ */
/* Close .mdf file */ /* Close .mdf file */
if (fclose(MdfF) !=0) { if (fclose(MdfF) !=0) {
printf("Error closing %s.car\n", rootname); printf("Error closing %s.car\n", rootname);
exit(1); exit(1);
} }
} /* End ReadMdfFile function */ } /* End ReadMdfFile function */
/*--------------------- get_molecule Function-----------------------*/ /*--------------------- get_molecule Function-----------------------*/
int get_molecule(char *line, int connect_col_no, int q_col_no, int get_molecule(char *line, int connect_col_no, int q_col_no,
int *counter) int *counter)
{ {
char *cur_field; /* For storing current string token */ char *cur_field; /* For storing current string token */
int i; /* Used in loop counters */ int i; /* Used in loop counters */
int connect_no; /* Connection number within atom */ int connect_no; /* Connection number within atom */
int r_val = 1; /* Return value. 1 = successful int r_val = 1; /* Return value. 1 = successful
0 = EOF encountered */ 0 = EOF encountered */
/* Loop over atoms */ /* Loop over atoms */
/* blank line signals end of molecule*/ /* blank line signals end of molecule*/
while(!blank_line(fgets(line,MAX_LINE_LENGTH,MdfF))) { while(!blank_line(fgets(line,MAX_LINE_LENGTH,MdfF))) {
/* while(strlen(fgets(line,MAX_LINE_LENGTH,MdfF)) > 2) { */ /* while(strlen(fgets(line,MAX_LINE_LENGTH,MdfF)) > 2) { */
clean_string(line); clean_string(line);
/* Get atom name */ /* Get atom name */
cur_field = strtok(line,":"); cur_field = strtok(line,":");
sscanf(cur_field, "%s", atoms[*counter].residue_string); sscanf(cur_field, "%s", atoms[*counter].residue_string);
cur_field = strtok(NULL," "); cur_field = strtok(NULL," ");
/* Compare atom name with that in .car file */ /* Compare atom name with that in .car file */
if (strcmp(atoms[*counter].name, cur_field)) { if (strcmp(atoms[*counter].name, cur_field)) {
fprintf(stderr,"Names %s from .car file and %s from .mdf file do not match\n", fprintf(stderr,"Names %s from .car file and %s from .mdf file do not match\n",
atoms[*counter].name, cur_field); atoms[*counter].name, cur_field);
fprintf(stderr,"counter = %d\n",*counter); fprintf(stderr,"counter = %d\n",*counter);
fprintf(stderr,"Program Terminating\n"); fprintf(stderr,"Program Terminating\n");
exit(4); exit(4);
} }
/* Skip unwanted fields until charge column, then update charge */ /* Skip unwanted fields until charge column, then update charge */
for (i=1; i < q_col_no; i++) strtok(NULL," "); for (i=1; i < q_col_no; i++) strtok(NULL," ");
cur_field = strtok(NULL, " "); cur_field = strtok(NULL, " ");
atoms[*counter].q = atof(cur_field); atoms[*counter].q = atof(cur_field);
/* Continue skipping unwanted fields until connectivity records begin */ /* Continue skipping unwanted fields until connectivity records begin */
for ( i = (q_col_no + 1); i < connect_col_no; i++) strtok(NULL," "); for ( i = (q_col_no + 1); i < connect_col_no; i++) strtok(NULL," ");
/* Process connections */ /* Process connections */
connect_no = 0; /* reset connections counter */ connect_no = 0; /* reset connections counter */
while ((cur_field = strtok(NULL," ")) && (connect_no < MAX_CONNECTIONS)) { while ((cur_field = strtok(NULL," ")) && (connect_no < MAX_CONNECTIONS)) {
sscanf(cur_field, "%s", atoms[*counter].connections[connect_no++]); sscanf(cur_field, "%s", atoms[*counter].connections[connect_no++]);
} }
atoms[*counter].no_connect = connect_no; atoms[*counter].no_connect = connect_no;
MakeConnectFullForm(counter); MakeConnectFullForm(counter);
(*counter)++; (*counter)++;
} /* End atom processing loop */ } /* End atom processing loop */
return r_val; return r_val;
} /* End get_molecule function */ } /* End get_molecule function */
/*------------------------MakeConnectFullForm Function--------------------*/ /*------------------------MakeConnectFullForm Function--------------------*/
void MakeConnectFullForm(int *counter) { void MakeConnectFullForm(int *counter) {
/* This function processes the connection names after all connections /* This function processes the connection names after all connections
for an atom have been read in. for an atom have been read in.
It replaces any short forms that use implied default values It replaces any short forms that use implied default values
with the full form connectivity record */ with the full form connectivity record */
int i; /* Counter for character array */ int i; /* Counter for character array */
int j; /* loop counter */ int j; /* loop counter */
char tempname[MAX_STRING]; /* name of connection */ char tempname[MAX_STRING]; /* name of connection */
char tempcell[10]; /* Values from connectivity record */ char tempcell[10]; /* Values from connectivity record */
char tempsym[5]; /* " " */ char tempsym[5]; /* " " */
char tempbo[6]; /* " " */ char tempbo[6]; /* " " */
char *charptr; char *charptr;
for ( j = 0; j < atoms[*counter].no_connect; j++) { for ( j = 0; j < atoms[*counter].no_connect; j++) {
/* If not full name, make name full */ /* If not full name, make name full */
if (strchr(atoms[*counter].connections[j],':') == NULL) { if (strchr(atoms[*counter].connections[j],':') == NULL) {
strcpy(tempname,atoms[*counter].residue_string); strcpy(tempname,atoms[*counter].residue_string);
strcat(tempname,":"); strcat(tempname,":");
strcat(tempname, strcat(tempname,
atoms[*counter].connections[j]); atoms[*counter].connections[j]);
sscanf(tempname, "%s", sscanf(tempname, "%s",
atoms[*counter].connections[j]); atoms[*counter].connections[j]);
} }
else else
sscanf(atoms[*counter].connections[j], "%s", tempname); sscanf(atoms[*counter].connections[j], "%s", tempname);
/* Set cell variables */ /* Set cell variables */
i=0; i=0;
charptr = (strchr(tempname,'%')); charptr = (strchr(tempname,'%'));
if (charptr != NULL) { if (charptr != NULL) {
while ( *charptr!='#' && *charptr!='/' && *charptr!='\000') while ( *charptr!='#' && *charptr!='/' && *charptr!='\000')
tempcell[i++] = *(charptr++); tempcell[i++] = *(charptr++);
tempcell[i] = '\000'; tempcell[i] = '\000';
} }
else else
strcpy(tempcell, "%000"); strcpy(tempcell, "%000");
/* Set symmetry variables /* Set symmetry variables
-- If not 1, cannot handle at this time */ -- If not 1, cannot handle at this time */
i = 0; i = 0;
charptr = (strchr(tempname,'#')); charptr = (strchr(tempname,'#'));
if (charptr != NULL) { if (charptr != NULL) {
while (*charptr != '/' && *charptr !='\000') { while (*charptr != '/' && *charptr !='\000') {
tempsym[i++] = *(charptr++); tempsym[i++] = *(charptr++);
if ((i==2) && (tempsym[1] != '1')) { if ((i==2) && (tempsym[1] != '1')) {
fprintf(stderr,"Msi2LMP is not equipped to handle symmetry operations\n"); fprintf(stderr,"Msi2LMP is not equipped to handle symmetry operations\n");
exit(5); exit(5);
} }
} }
tempsym[i] = '\000'; tempsym[i] = '\000';
} }
else else
strcpy(tempsym, "#1"); strcpy(tempsym, "#1");
/* Set bond order and record in data structure */ /* Set bond order and record in data structure */
i = 0; i = 0;
charptr = strchr(tempname,'/'); charptr = strchr(tempname,'/');
if (charptr != NULL) { if (charptr != NULL) {
charptr++; charptr++;
while (*charptr != '\000') while (*charptr != '\000')
tempbo[i++] = *(charptr++); tempbo[i++] = *(charptr++);
tempbo[i] = '\000'; tempbo[i] = '\000';
} }
else else
strcpy(tempbo, "1.0"); strcpy(tempbo, "1.0");
atoms[*counter].bond_order[j] = atof(tempbo); atoms[*counter].bond_order[j] = atof(tempbo);
/* Build connection name and store in atoms data structure */ /* Build connection name and store in atoms data structure */
strtok( tempname, "%#/"); strtok( tempname, "%#/");
strcat( tempname, tempcell); strcat( tempname, tempcell);
strcat( tempname, tempsym); strcat( tempname, tempsym);
strcat( tempname, "/"); strcat( tempname, "/");
strcat( tempname, tempbo); strcat( tempname, tempbo);
if (strlen(tempname) > 25) fprintf(stderr,"tempname overrun %s\n",tempname); if (strlen(tempname) > 25) fprintf(stderr,"tempname overrun %s\n",tempname);
sscanf( tempname, "%s", atoms[*counter].connections[j]); sscanf( tempname, "%s", atoms[*counter].connections[j]);
}/*End for loop*/ }/*End for loop*/
}/* End function MakeNameLong }/* End function MakeNameLong
*/ */
void clean_string(char *string) { void clean_string(char *string) {
int i,n; int i,n;
short k; short k;
n = strlen(string); n = strlen(string);
for (i=0; i < n; i++) { for (i=0; i < n; i++) {
k = (short)string[i]; k = (short)string[i];
if ((k<32) | (k>127)) string[i] = '\0'; if ((k<32) | (k>127)) string[i] = '\0';
} }
} }

View File

@ -1,218 +1,218 @@
/**************************** /****************************
* *
* This function first allocates memory to the forcefield item * This function first allocates memory to the forcefield item
* structures and then reads parameters from the forcefield file into the * structures and then reads parameters from the forcefield file into the
* allocated memory * allocated memory
* *
*/ */
#include "Forcefield.h" #include "Forcefield.h"
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
unsigned char string_match(char *,char *); unsigned char string_match(char *,char *);
void SearchAndFill(struct FrcFieldItem *item) void SearchAndFill(struct FrcFieldItem *item)
{ {
int i,j; /* counters */ int i,j; /* counters */
int got_it = 0; int got_it = 0;
int ctr = 0; int ctr = 0;
long file_pos; long file_pos;
char line[MAX_LINE] = "empty"; char line[MAX_LINE] = "empty";
char *charptr,*status; char *charptr,*status;
extern FILE *FrcF; extern FILE *FrcF;
/***********************ALLOCATE MEMORY FOR STRUCTURE ********************/ /***********************ALLOCATE MEMORY FOR STRUCTURE ********************/
/* Read and discard lines until keyword is found */ /* Read and discard lines until keyword is found */
rewind(FrcF); rewind(FrcF);
while ((got_it == 0)) { while ((got_it == 0)) {
status = fgets( line, MAX_LINE, FrcF ); status = fgets( line, MAX_LINE, FrcF );
if (status == NULL) { if (status == NULL) {
fprintf(stderr," Unable to find forcefield keyword %s\n",item->keyword); fprintf(stderr," Unable to find forcefield keyword %s\n",item->keyword);
fprintf(stderr," Check consistency of forcefield name and class \n"); fprintf(stderr," Check consistency of forcefield name and class \n");
fprintf(stderr," Exiting....\n"); fprintf(stderr," Exiting....\n");
exit(1); exit(1);
} }
if (line[0] == '#') { if (line[0] == '#') {
if (string_match(strtok(line," '\t'("),item->keyword)) got_it = 1; if (string_match(strtok(line," '\t'("),item->keyword)) got_it = 1;
} }
/* if (strncmp(line, item->keyword,strlen(item->keyword))==0) got_it = 1; */ /* if (strncmp(line, item->keyword,strlen(item->keyword))==0) got_it = 1; */
} }
file_pos = ftell(FrcF); file_pos = ftell(FrcF);
/* Count the number of lines until next item is found */ /* Count the number of lines until next item is found */
while( strncmp(fgets(line,MAX_LINE,FrcF), "#", 1) != 0 ) while( strncmp(fgets(line,MAX_LINE,FrcF), "#", 1) != 0 )
ctr++; ctr++;
/* Allocate the memory using calloc */ /* Allocate the memory using calloc */
item->data = calloc(ctr, sizeof(struct FrcFieldData)); item->data = calloc(ctr, sizeof(struct FrcFieldData));
if (item->data == NULL) { if (item->data == NULL) {
fprintf(stderr,"Could not allocate memory to %s\n", item->keyword); fprintf(stderr,"Could not allocate memory to %s\n", item->keyword);
exit(2); exit(2);
} }
/********************FILL PARAMETERS AND EQUIVALENCES ********************/ /********************FILL PARAMETERS AND EQUIVALENCES ********************/
/* Read lines until keyword is found */ /* Read lines until keyword is found */
fseek(FrcF,file_pos,SEEK_SET); fseek(FrcF,file_pos,SEEK_SET);
strcpy(line,"empty"); strcpy(line,"empty");
/* Read lines until data starts (when !--- is found) */ /* Read lines until data starts (when !--- is found) */
ctr = 0; ctr = 0;
while ( strncmp(line,"!---", 4) != 0 ) { while ( strncmp(line,"!---", 4) != 0 ) {
fgets(line, MAX_LINE, FrcF); fgets(line, MAX_LINE, FrcF);
} }
/* Get first line of data that isn't commented out */ /* Get first line of data that isn't commented out */
fgets(line, MAX_LINE, FrcF); fgets(line, MAX_LINE, FrcF);
while (strncmp(line,"!",1) == 0) { while (strncmp(line,"!",1) == 0) {
fgets( line, MAX_LINE, FrcF); fgets( line, MAX_LINE, FrcF);
} }
/* Read data into structure */ /* Read data into structure */
while( strncmp( line, "#", 1 ) != 0 ) { while( strncmp( line, "#", 1 ) != 0 ) {
float version; float version;
int reference,replace; int reference,replace;
char atom_types[5][5]; char atom_types[5][5];
double parameters[8]; double parameters[8];
/* version number and reference number */ /* version number and reference number */
version = atof(strtok(line, " ")); version = atof(strtok(line, " "));
reference = atoi(strtok(NULL, " ")); reference = atoi(strtok(NULL, " "));
/* equivalences */ /* equivalences */
for(i = 0; i < item->number_of_members; i++ ) { for(i = 0; i < item->number_of_members; i++ ) {
sscanf(strtok(NULL, " "), "%s", atom_types[i]); sscanf(strtok(NULL, " "), "%s", atom_types[i]);
} }
/* parameters -- Because of symmetrical terms, bonang, angtor, and /* parameters -- Because of symmetrical terms, bonang, angtor, and
endbontor have to be treated carefully */ endbontor have to be treated carefully */
for( i = 0; i < item->number_of_parameters; i++ ) { for( i = 0; i < item->number_of_parameters; i++ ) {
charptr = strtok(NULL, " "); charptr = strtok(NULL, " ");
if(charptr == NULL) { if(charptr == NULL) {
for ( j = i; j < item->number_of_parameters; j++ ) for ( j = i; j < item->number_of_parameters; j++ )
parameters[j] = parameters[j-i]; parameters[j] = parameters[j-i];
break; break;
} }
else { else {
parameters[i] = atof(charptr); parameters[i] = atof(charptr);
} }
} }
/* Search for matching sets of atom types. /* Search for matching sets of atom types.
If found and the version number is greater, substitute If found and the version number is greater, substitute
the current set of parameters in place of the found set. the current set of parameters in place of the found set.
Otherwise, add the current set of parameters to the Otherwise, add the current set of parameters to the
list. list.
*/ */
replace = ctr; replace = ctr;
for (j=0; j < ctr; j++) { for (j=0; j < ctr; j++) {
int k=0; int k=0;
int match = 1; int match = 1;
while (match && (k < item->number_of_members)) { while (match && (k < item->number_of_members)) {
if (strncmp(item->data[j].ff_types[k],atom_types[k],5) == 0) if (strncmp(item->data[j].ff_types[k],atom_types[k],5) == 0)
k++; k++;
else else
match = 0; match = 0;
} }
if (match == 1) { if (match == 1) {
replace = j; replace = j;
break; break;
} }
} }
if (replace != ctr) { if (replace != ctr) {
if (version > item->data[replace].ver) { if (version > item->data[replace].ver) {
if (pflag > 1) { if (pflag > 1) {
fprintf(stderr," Using higher version of parameters for"); fprintf(stderr," Using higher version of parameters for");
fprintf(stderr," %s ",item->keyword); fprintf(stderr," %s ",item->keyword);
for (i=0; i < item->number_of_members; i++) for (i=0; i < item->number_of_members; i++)
fprintf(stderr,"%s ",atom_types[i]); fprintf(stderr,"%s ",atom_types[i]);
fprintf(stderr," version %3.2f\n",version); fprintf(stderr," version %3.2f\n",version);
} }
item->data[replace].ver = version; item->data[replace].ver = version;
item->data[replace].ref = reference; item->data[replace].ref = reference;
for (i=0; i < item->number_of_members; i++) { for (i=0; i < item->number_of_members; i++) {
strncpy(item->data[replace].ff_types[i],atom_types[i],5); strncpy(item->data[replace].ff_types[i],atom_types[i],5);
} }
for (i=0; i < item->number_of_parameters; i++) { for (i=0; i < item->number_of_parameters; i++) {
item->data[replace].ff_param[i] = parameters[i]; item->data[replace].ff_param[i] = parameters[i];
} }
} }
else { else {
if (pflag > 1) { if (pflag > 1) {
fprintf(stderr," Using higher version of parameters for"); fprintf(stderr," Using higher version of parameters for");
fprintf(stderr," %s ",item->keyword); fprintf(stderr," %s ",item->keyword);
for (i=0; i < item->number_of_members; i++) for (i=0; i < item->number_of_members; i++)
fprintf(stderr,"%s ",item->data[replace].ff_types[i]); fprintf(stderr,"%s ",item->data[replace].ff_types[i]);
fprintf(stderr," version %3.2f\n",item->data[replace].ver); fprintf(stderr," version %3.2f\n",item->data[replace].ver);
} }
} }
} }
else { else {
item->data[ctr].ver = version; item->data[ctr].ver = version;
item->data[ctr].ref = reference; item->data[ctr].ref = reference;
for (i=0; i < item->number_of_members; i++) { for (i=0; i < item->number_of_members; i++) {
strncpy(item->data[ctr].ff_types[i],atom_types[i],5); strncpy(item->data[ctr].ff_types[i],atom_types[i],5);
} }
for (i=0; i < item->number_of_parameters; i++) { for (i=0; i < item->number_of_parameters; i++) {
item->data[ctr].ff_param[i] = parameters[i]; item->data[ctr].ff_param[i] = parameters[i];
} }
ctr++; ctr++;
} }
fgets( line, MAX_LINE, FrcF); fgets( line, MAX_LINE, FrcF);
/*if blank line encountered, get next */ /*if blank line encountered, get next */
while((blank_line(line)) || while((blank_line(line)) ||
(strncmp(line,"!",1) == 0)) { (strncmp(line,"!",1) == 0)) {
fgets( line, MAX_LINE, FrcF); fgets( line, MAX_LINE, FrcF);
} }
} }
item->entries = ctr; item->entries = ctr;
/*Debugging /*Debugging
fprintf(stderr,"\n%s\n", item->keyword); fprintf(stderr,"\n%s\n", item->keyword);
for(i=0;i<ctr;i++) { for(i=0;i<ctr;i++) {
for(j=0;j<item->number_of_members;j++) for(j=0;j<item->number_of_members;j++)
fprintf(stderr,"%3s ", item->data[i].ff_equiv[j]); fprintf(stderr,"%3s ", item->data[i].ff_equiv[j]);
fprintf(stderr," "); fprintf(stderr," ");
for(j=0;j<item->number_of_parameters;j++) for(j=0;j<item->number_of_parameters;j++)
fprintf(stderr,"%10.5f ",item->data[i].ff_param[j]); fprintf(stderr,"%10.5f ",item->data[i].ff_param[j]);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
*/ */
} }
unsigned char string_match(char *string1,char *string2) unsigned char string_match(char *string1,char *string2)
{ {
int len1,len2; int len1,len2;
len1 = strlen(string1); len1 = strlen(string1);
len2 = strlen(string2); len2 = strlen(string2);
if (len1 != len2) { if (len1 != len2) {
return 0; return 0;
} }
else { else {
if (strncmp(string1,string2,len1) == 0) { if (strncmp(string1,string2,len1) == 0) {
return 1; return 1;
} }
else { else {
return 0; return 0;
} }
} }
} }

View File

@ -1,313 +1,313 @@
/* /*
* This function creates and writes the data file to be used with LAMMPS * This function creates and writes the data file to be used with LAMMPS
*/ */
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
#include "Forcefield.h" #include "Forcefield.h"
void WriteDataFile(FILE *DatF,char *nameroot,int forcefield) void WriteDataFile(FILE *DatF,char *nameroot,int forcefield)
{ {
int i,j,k,m; int i,j,k,m;
char line[MAX_LINE_LENGTH]; char line[MAX_LINE_LENGTH];
if (forcefield == 1) total_no_angle_angles = 0; if (forcefield == 1) total_no_angle_angles = 0;
fprintf(DatF, "LAMMPS data file for %s\n\n", nameroot); fprintf(DatF, "LAMMPS data file for %s\n\n", nameroot);
fprintf(DatF, " %6d atoms\n", total_no_atoms); fprintf(DatF, " %6d atoms\n", total_no_atoms);
fprintf(DatF, " %6d bonds\n", total_no_bonds); fprintf(DatF, " %6d bonds\n", total_no_bonds);
fprintf(DatF, " %6d angles\n",total_no_angles); fprintf(DatF, " %6d angles\n",total_no_angles);
fprintf(DatF, " %6d dihedrals\n", total_no_dihedrals); fprintf(DatF, " %6d dihedrals\n", total_no_dihedrals);
fprintf(DatF, " %6d impropers\n", total_no_oops+total_no_angle_angles); fprintf(DatF, " %6d impropers\n", total_no_oops+total_no_angle_angles);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF, " %3d atom types\n", no_atom_types); fprintf(DatF, " %3d atom types\n", no_atom_types);
if (no_bond_types > 0) if (no_bond_types > 0)
fprintf(DatF, " %3d bond types\n", no_bond_types); fprintf(DatF, " %3d bond types\n", no_bond_types);
if (no_angle_types> 0) if (no_angle_types> 0)
fprintf(DatF, " %3d angle types\n", no_angle_types); fprintf(DatF, " %3d angle types\n", no_angle_types);
if (no_dihedral_types > 0) fprintf (DatF," %3d dihedral types\n", if (no_dihedral_types > 0) fprintf (DatF," %3d dihedral types\n",
no_dihedral_types); no_dihedral_types);
if (forcefield > 1) { if (forcefield > 1) {
if ((no_oop_types + no_angleangle_types) > 0) if ((no_oop_types + no_angleangle_types) > 0)
fprintf (DatF, " %3d improper types\n", fprintf (DatF, " %3d improper types\n",
no_oop_types + no_angleangle_types); no_oop_types + no_angleangle_types);
} }
else { else {
if (no_oop_types > 0) if (no_oop_types > 0)
fprintf (DatF, " %3d improper types\n", no_oop_types); fprintf (DatF, " %3d improper types\n", no_oop_types);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF, " %15.9f %15.9f xlo xhi\n", pbc[0], pbc[3]); fprintf(DatF, " %15.9f %15.9f xlo xhi\n", pbc[0], pbc[3]);
fprintf(DatF, " %15.9f %15.9f ylo yhi\n", pbc[1], pbc[4]); fprintf(DatF, " %15.9f %15.9f ylo yhi\n", pbc[1], pbc[4]);
fprintf(DatF, " %15.9f %15.9f zlo zhi\n", pbc[2], pbc[5]); fprintf(DatF, " %15.9f %15.9f zlo zhi\n", pbc[2], pbc[5]);
/* MASSES */ /* MASSES */
fprintf(DatF, "\nMasses\n\n"); fprintf(DatF, "\nMasses\n\n");
for(k=0; k < no_atom_types; k++) for(k=0; k < no_atom_types; k++)
fprintf(DatF, " %3d %10.6f\n",k+1,atomtypes[k].mass); fprintf(DatF, " %3d %10.6f\n",k+1,atomtypes[k].mass);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
/* COEFFICIENTS */ /* COEFFICIENTS */
fprintf(DatF,"Nonbond Coeffs\n\n"); fprintf(DatF,"Nonbond Coeffs\n\n");
for (i=0; i < no_atom_types; i++) { for (i=0; i < no_atom_types; i++) {
fprintf(DatF, " %3i ", i+1); fprintf(DatF, " %3i ", i+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%14.10f ", atomtypes[i].params[j]); fprintf(DatF, "%14.10f ", atomtypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
if (no_bond_types > 0) { if (no_bond_types > 0) {
if (forcefield == 1) m = 2; if (forcefield == 1) m = 2;
if (forcefield == 2) m = 4; if (forcefield == 2) m = 4;
fprintf(DatF,"Bond Coeffs\n\n"); fprintf(DatF,"Bond Coeffs\n\n");
for (i=0; i < no_bond_types; i++) { for (i=0; i < no_bond_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", bondtypes[i].params[j]); fprintf(DatF, "%10.4f ", bondtypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_angle_types > 0) { if (no_angle_types > 0) {
if (forcefield == 1) m = 2; if (forcefield == 1) m = 2;
if (forcefield == 2) m = 4; if (forcefield == 2) m = 4;
fprintf(DatF,"Angle Coeffs\n\n"); fprintf(DatF,"Angle Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", angletypes[i].params[j]); fprintf(DatF, "%10.4f ", angletypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_dihedral_types > 0) { if (no_dihedral_types > 0) {
if (forcefield == 1) m = 3; if (forcefield == 1) m = 3;
if (forcefield == 2) m = 6; if (forcefield == 2) m = 6;
fprintf(DatF,"Dihedral Coeffs\n\n"); fprintf(DatF,"Dihedral Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", dihedraltypes[i].params[j]); fprintf(DatF, "%10.4f ", dihedraltypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (forcefield == 1) { if (forcefield == 1) {
if (no_oop_types > 0) { if (no_oop_types > 0) {
fprintf(DatF,"Improper Coeffs\n\n"); fprintf(DatF,"Improper Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
else if (forcefield == 2) { else if (forcefield == 2) {
if ((no_oop_types + no_angleangle_types) > 0) { if ((no_oop_types + no_angleangle_types) > 0) {
fprintf(DatF,"Improper Coeffs\n\n"); fprintf(DatF,"Improper Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
for (i=0; i < no_angleangle_types; i++) { for (i=0; i < no_angleangle_types; i++) {
fprintf(DatF, "%3i ", i+no_oop_types+1); fprintf(DatF, "%3i ", i+no_oop_types+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%10.4f ", 0.0); fprintf(DatF, "%10.4f ", 0.0);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
if (forcefield == 2) { if (forcefield == 2) {
if (no_angle_types > 0) { if (no_angle_types > 0) {
fprintf(DatF,"BondBond Coeffs\n\n"); fprintf(DatF,"BondBond Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", angletypes[i].bondbond_cross_term[j]); fprintf(DatF, "%10.4f ", angletypes[i].bondbond_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"BondAngle Coeffs\n\n"); fprintf(DatF,"BondAngle Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 4; j++) for ( j = 0; j < 4; j++)
fprintf(DatF, "%10.4f ",angletypes[i].bondangle_cross_term[j]); fprintf(DatF, "%10.4f ",angletypes[i].bondangle_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if ((no_oop_types+no_angleangle_types) > 0) { if ((no_oop_types+no_angleangle_types) > 0) {
fprintf(DatF,"AngleAngle Coeffs\n\n"); fprintf(DatF,"AngleAngle Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 6; j++) for ( j = 0; j < 6; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].angleangle_params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].angleangle_params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
for (i=0; i < no_angleangle_types; i++) { for (i=0; i < no_angleangle_types; i++) {
fprintf(DatF, "%3i ", i+no_oop_types+1); fprintf(DatF, "%3i ", i+no_oop_types+1);
for ( j = 0; j < 6; j++) for ( j = 0; j < 6; j++)
fprintf(DatF, "%10.4f ", angleangletypes[i].params[j]); fprintf(DatF, "%10.4f ", angleangletypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_dihedral_types > 0) { if (no_dihedral_types > 0) {
fprintf(DatF,"AngleAngleTorsion Coeffs\n\n"); fprintf(DatF,"AngleAngleTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF,"%10.4f ", fprintf(DatF,"%10.4f ",
dihedraltypes[i].angleangledihedral_cross_term[j]); dihedraltypes[i].angleangledihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"EndBondTorsion Coeffs\n\n"); fprintf(DatF,"EndBondTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%i ", i+1); fprintf(DatF, "%i ", i+1);
for ( j = 0; j < 8; j++) for ( j = 0; j < 8; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].endbonddihedral_cross_term[j]); dihedraltypes[i].endbonddihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"MiddleBondTorsion Coeffs\n\n"); fprintf(DatF,"MiddleBondTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 4; j++) for ( j = 0; j < 4; j++)
fprintf(DatF,"%10.4f ", fprintf(DatF,"%10.4f ",
dihedraltypes[i].midbonddihedral_cross_term[j]); dihedraltypes[i].midbonddihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"BondBond13 Coeffs\n\n"); fprintf(DatF,"BondBond13 Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].bond13_cross_term[j]); dihedraltypes[i].bond13_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"AngleTorsion Coeffs\n\n"); fprintf(DatF,"AngleTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 8; j++) for ( j = 0; j < 8; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].angledihedral_cross_term[j]); dihedraltypes[i].angledihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* ATOMS */ /* ATOMS */
fprintf(DatF, "Atoms\n\n"); fprintf(DatF, "Atoms\n\n");
for(k=0; k < total_no_atoms; k++) { for(k=0; k < total_no_atoms; k++) {
fprintf(DatF, " %6i %6i %3i %9.6f %15.9f %15.9f %15.9f\n", fprintf(DatF, " %6i %6i %3i %9.6f %15.9f %15.9f %15.9f\n",
k+1, k+1,
atoms[k].molecule, atoms[k].molecule,
atoms[k].type+1, atoms[k].type+1,
atoms[k].q, atoms[k].q,
atoms[k].x[0], atoms[k].x[0],
atoms[k].x[1], atoms[k].x[1],
atoms[k].x[2]); atoms[k].x[2]);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
/***** BONDS *****/ /***** BONDS *****/
if (total_no_bonds > 0) { if (total_no_bonds > 0) {
fprintf(DatF, "Bonds\n\n"); fprintf(DatF, "Bonds\n\n");
for(k=0; k < total_no_bonds; k++) for(k=0; k < total_no_bonds; k++)
fprintf(DatF, "%6i %3i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i\n",k+1,
bonds[k].type+1, bonds[k].type+1,
bonds[k].members[0]+1, bonds[k].members[0]+1,
bonds[k].members[1]+1); bonds[k].members[1]+1);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
/***** ANGLES *****/ /***** ANGLES *****/
if (total_no_angles > 0) { if (total_no_angles > 0) {
fprintf(DatF, "Angles\n\n"); fprintf(DatF, "Angles\n\n");
for(k=0; k < total_no_angles; k++) for(k=0; k < total_no_angles; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i %6i\n",k+1,
angles[k].type+1, angles[k].type+1,
angles[k].members[0]+1, angles[k].members[0]+1,
angles[k].members[1]+1, angles[k].members[1]+1,
angles[k].members[2]+1); angles[k].members[2]+1);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/***** TORSIONS *****/ /***** TORSIONS *****/
if (total_no_dihedrals > 0) { if (total_no_dihedrals > 0) {
fprintf(DatF,"Dihedrals\n\n"); fprintf(DatF,"Dihedrals\n\n");
for(k=0; k < total_no_dihedrals; k++) for(k=0; k < total_no_dihedrals; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i\n",k+1,
dihedrals[k].type+1, dihedrals[k].type+1,
dihedrals[k].members[0]+1, dihedrals[k].members[0]+1,
dihedrals[k].members[1]+1, dihedrals[k].members[1]+1,
dihedrals[k].members[2]+1, dihedrals[k].members[2]+1,
dihedrals[k].members[3]+1); dihedrals[k].members[3]+1);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/***** OUT-OF-PLANES *****/ /***** OUT-OF-PLANES *****/
if (total_no_oops+total_no_angle_angles > 0) { if (total_no_oops+total_no_angle_angles > 0) {
fprintf(DatF,"Impropers\n\n"); fprintf(DatF,"Impropers\n\n");
for (k=0; k < total_no_oops; k++) for (k=0; k < total_no_oops; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n", k+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n", k+1,
oops[k].type+1, oops[k].type+1,
oops[k].members[0]+1, oops[k].members[0]+1,
oops[k].members[1]+1, oops[k].members[1]+1,
oops[k].members[2]+1, oops[k].members[2]+1,
oops[k].members[3]+1); oops[k].members[3]+1);
if (forcefield == 2) { if (forcefield == 2) {
for (k=0; k < total_no_angle_angles; k++) for (k=0; k < total_no_angle_angles; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n",k+total_no_oops+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n",k+total_no_oops+1,
angleangles[k].type+no_oop_types+1, angleangles[k].type+no_oop_types+1,
angleangles[k].members[0]+1, angleangles[k].members[0]+1,
angleangles[k].members[1]+1, angleangles[k].members[1]+1,
angleangles[k].members[2]+1, angleangles[k].members[2]+1,
angleangles[k].members[3]+1); angleangles[k].members[3]+1);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }

View File

@ -1,332 +1,332 @@
/* /*
* This function creates and writes the data file to be used with LAMMPS * This function creates and writes the data file to be used with LAMMPS
*/ */
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
#include "Forcefield.h" #include "Forcefield.h"
void WriteDataFile01(char *nameroot,int forcefield) void WriteDataFile01(char *nameroot,int forcefield)
{ {
int i,j,k,m; int i,j,k,m;
char line[MAX_LINE_LENGTH]; char line[MAX_LINE_LENGTH];
FILE *DatF; FILE *DatF;
/* Open data file */ /* Open data file */
sprintf(line,"%s.lammps01",rootname); sprintf(line,"%s.lammps01",rootname);
if (pflag > 0) fprintf(stderr," Writing LAMMPS 2001 data file: %s\n",line); if (pflag > 0) fprintf(stderr," Writing LAMMPS 2001 data file: %s\n",line);
if( (DatF = fopen(line,"w")) == NULL ) { if( (DatF = fopen(line,"w")) == NULL ) {
fprintf(stderr,"Cannot open %s\n",line); fprintf(stderr,"Cannot open %s\n",line);
exit(2); exit(2);
} }
if (forcefield == 1) total_no_angle_angles = 0; if (forcefield == 1) total_no_angle_angles = 0;
fprintf(DatF, "LAMMPS data file for %s\n\n", nameroot); fprintf(DatF, "LAMMPS data file for %s\n\n", nameroot);
fprintf(DatF, " %6d atoms\n", total_no_atoms); fprintf(DatF, " %6d atoms\n", total_no_atoms);
fprintf(DatF, " %6d bonds\n", total_no_bonds); fprintf(DatF, " %6d bonds\n", total_no_bonds);
fprintf(DatF, " %6d angles\n",total_no_angles); fprintf(DatF, " %6d angles\n",total_no_angles);
fprintf(DatF, " %6d dihedrals\n", total_no_dihedrals); fprintf(DatF, " %6d dihedrals\n", total_no_dihedrals);
fprintf(DatF, " %6d impropers\n", total_no_oops+total_no_angle_angles); fprintf(DatF, " %6d impropers\n", total_no_oops+total_no_angle_angles);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF, " %3d atom types\n", no_atom_types); fprintf(DatF, " %3d atom types\n", no_atom_types);
if (no_bond_types > 0) if (no_bond_types > 0)
fprintf(DatF, " %3d bond types\n", no_bond_types); fprintf(DatF, " %3d bond types\n", no_bond_types);
if (no_angle_types> 0) if (no_angle_types> 0)
fprintf(DatF, " %3d angle types\n", no_angle_types); fprintf(DatF, " %3d angle types\n", no_angle_types);
if (no_dihedral_types > 0) fprintf (DatF," %3d dihedral types\n", if (no_dihedral_types > 0) fprintf (DatF," %3d dihedral types\n",
no_dihedral_types); no_dihedral_types);
if (forcefield > 1) { if (forcefield > 1) {
if ((no_oop_types + no_angleangle_types) > 0) if ((no_oop_types + no_angleangle_types) > 0)
fprintf (DatF, " %3d improper types\n", fprintf (DatF, " %3d improper types\n",
no_oop_types + no_angleangle_types); no_oop_types + no_angleangle_types);
} }
else { else {
if (no_oop_types > 0) if (no_oop_types > 0)
fprintf (DatF, " %3d improper types\n", no_oop_types); fprintf (DatF, " %3d improper types\n", no_oop_types);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF, " %15.9f %15.9f xlo xhi\n", pbc[0], pbc[3]); fprintf(DatF, " %15.9f %15.9f xlo xhi\n", pbc[0], pbc[3]);
fprintf(DatF, " %15.9f %15.9f ylo yhi\n", pbc[1], pbc[4]); fprintf(DatF, " %15.9f %15.9f ylo yhi\n", pbc[1], pbc[4]);
fprintf(DatF, " %15.9f %15.9f zlo zhi\n", pbc[2], pbc[5]); fprintf(DatF, " %15.9f %15.9f zlo zhi\n", pbc[2], pbc[5]);
/* MASSES */ /* MASSES */
fprintf(DatF, "\nMasses\n\n"); fprintf(DatF, "\nMasses\n\n");
for(k=0; k < no_atom_types; k++) for(k=0; k < no_atom_types; k++)
fprintf(DatF, " %3d %10.6f\n",k+1,atomtypes[k].mass); fprintf(DatF, " %3d %10.6f\n",k+1,atomtypes[k].mass);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
/* COEFFICIENTS */ /* COEFFICIENTS */
fprintf(DatF,"Nonbond Coeffs\n\n"); fprintf(DatF,"Nonbond Coeffs\n\n");
for (i=0; i < no_atom_types; i++) { for (i=0; i < no_atom_types; i++) {
fprintf(DatF, " %3i ", i+1); fprintf(DatF, " %3i ", i+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%14.10f ", atomtypes[i].params[j]); fprintf(DatF, "%14.10f ", atomtypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
if (no_bond_types > 0) { if (no_bond_types > 0) {
if (forcefield == 1) m = 2; if (forcefield == 1) m = 2;
if (forcefield == 2) m = 4; if (forcefield == 2) m = 4;
fprintf(DatF,"Bond Coeffs\n\n"); fprintf(DatF,"Bond Coeffs\n\n");
for (i=0; i < no_bond_types; i++) { for (i=0; i < no_bond_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", bondtypes[i].params[j]); fprintf(DatF, "%10.4f ", bondtypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_angle_types > 0) { if (no_angle_types > 0) {
if (forcefield == 1) m = 2; if (forcefield == 1) m = 2;
if (forcefield == 2) m = 4; if (forcefield == 2) m = 4;
fprintf(DatF,"Angle Coeffs\n\n"); fprintf(DatF,"Angle Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", angletypes[i].params[j]); fprintf(DatF, "%10.4f ", angletypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_dihedral_types > 0) { if (no_dihedral_types > 0) {
if (forcefield == 1) m = 3; if (forcefield == 1) m = 3;
if (forcefield == 2) m = 6; if (forcefield == 2) m = 6;
fprintf(DatF,"Dihedral Coeffs\n\n"); fprintf(DatF,"Dihedral Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", dihedraltypes[i].params[j]); fprintf(DatF, "%10.4f ", dihedraltypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (forcefield == 1) { if (forcefield == 1) {
if (no_oop_types > 0) { if (no_oop_types > 0) {
fprintf(DatF,"Improper Coeffs\n\n"); fprintf(DatF,"Improper Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
else if (forcefield == 2) { else if (forcefield == 2) {
if ((no_oop_types + no_angleangle_types) > 0) { if ((no_oop_types + no_angleangle_types) > 0) {
fprintf(DatF,"Improper Coeffs\n\n"); fprintf(DatF,"Improper Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
for (i=0; i < no_angleangle_types; i++) { for (i=0; i < no_angleangle_types; i++) {
fprintf(DatF, "%3i ", i+no_oop_types+1); fprintf(DatF, "%3i ", i+no_oop_types+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%10.4f ", 0.0); fprintf(DatF, "%10.4f ", 0.0);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
if (forcefield == 2) { if (forcefield == 2) {
if (no_angle_types > 0) { if (no_angle_types > 0) {
fprintf(DatF,"BondBond Coeffs\n\n"); fprintf(DatF,"BondBond Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", angletypes[i].bondbond_cross_term[j]); fprintf(DatF, "%10.4f ", angletypes[i].bondbond_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"BondAngle Coeffs\n\n"); fprintf(DatF,"BondAngle Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 4; j++) for ( j = 0; j < 4; j++)
fprintf(DatF, "%10.4f ",angletypes[i].bondangle_cross_term[j]); fprintf(DatF, "%10.4f ",angletypes[i].bondangle_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if ((no_oop_types+no_angleangle_types) > 0) { if ((no_oop_types+no_angleangle_types) > 0) {
fprintf(DatF,"AngleAngle Coeffs\n\n"); fprintf(DatF,"AngleAngle Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 6; j++) for ( j = 0; j < 6; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].angleangle_params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].angleangle_params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
for (i=0; i < no_angleangle_types; i++) { for (i=0; i < no_angleangle_types; i++) {
fprintf(DatF, "%3i ", i+no_oop_types+1); fprintf(DatF, "%3i ", i+no_oop_types+1);
for ( j = 0; j < 6; j++) for ( j = 0; j < 6; j++)
fprintf(DatF, "%10.4f ", angleangletypes[i].params[j]); fprintf(DatF, "%10.4f ", angleangletypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_dihedral_types > 0) { if (no_dihedral_types > 0) {
fprintf(DatF,"AngleAngleTorsion Coeffs\n\n"); fprintf(DatF,"AngleAngleTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF,"%10.4f ", fprintf(DatF,"%10.4f ",
dihedraltypes[i].angleangledihedral_cross_term[j]); dihedraltypes[i].angleangledihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"EndBondTorsion Coeffs\n\n"); fprintf(DatF,"EndBondTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%i ", i+1); fprintf(DatF, "%i ", i+1);
for ( j = 0; j < 8; j++) for ( j = 0; j < 8; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].endbonddihedral_cross_term[j]); dihedraltypes[i].endbonddihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"MiddleBondTorsion Coeffs\n\n"); fprintf(DatF,"MiddleBondTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 4; j++) for ( j = 0; j < 4; j++)
fprintf(DatF,"%10.4f ", fprintf(DatF,"%10.4f ",
dihedraltypes[i].midbonddihedral_cross_term[j]); dihedraltypes[i].midbonddihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"BondBond13 Coeffs\n\n"); fprintf(DatF,"BondBond13 Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].bond13_cross_term[j]); dihedraltypes[i].bond13_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"AngleTorsion Coeffs\n\n"); fprintf(DatF,"AngleTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 8; j++) for ( j = 0; j < 8; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].angledihedral_cross_term[j]); dihedraltypes[i].angledihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* ATOMS */ /* ATOMS */
fprintf(DatF, "Atoms\n\n"); fprintf(DatF, "Atoms\n\n");
for(k=0; k < total_no_atoms; k++) { for(k=0; k < total_no_atoms; k++) {
fprintf(DatF, " %6i %6i %3i %9.6f %15.9f %15.9f %15.9f\n", fprintf(DatF, " %6i %6i %3i %9.6f %15.9f %15.9f %15.9f\n",
k+1, k+1,
atoms[k].molecule, atoms[k].molecule,
atoms[k].type+1, atoms[k].type+1,
atoms[k].q, atoms[k].q,
atoms[k].x[0], atoms[k].x[0],
atoms[k].x[1], atoms[k].x[1],
atoms[k].x[2]); atoms[k].x[2]);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
/***** BONDS *****/ /***** BONDS *****/
if (total_no_bonds > 0) { if (total_no_bonds > 0) {
fprintf(DatF, "Bonds\n\n"); fprintf(DatF, "Bonds\n\n");
for(k=0; k < total_no_bonds; k++) for(k=0; k < total_no_bonds; k++)
fprintf(DatF, "%6i %3i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i\n",k+1,
bonds[k].type+1, bonds[k].type+1,
bonds[k].members[0]+1, bonds[k].members[0]+1,
bonds[k].members[1]+1); bonds[k].members[1]+1);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
/***** ANGLES *****/ /***** ANGLES *****/
if (total_no_angles > 0) { if (total_no_angles > 0) {
fprintf(DatF, "Angles\n\n"); fprintf(DatF, "Angles\n\n");
for(k=0; k < total_no_angles; k++) for(k=0; k < total_no_angles; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i %6i\n",k+1,
angles[k].type+1, angles[k].type+1,
angles[k].members[0]+1, angles[k].members[0]+1,
angles[k].members[1]+1, angles[k].members[1]+1,
angles[k].members[2]+1); angles[k].members[2]+1);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/***** TORSIONS *****/ /***** TORSIONS *****/
if (total_no_dihedrals > 0) { if (total_no_dihedrals > 0) {
fprintf(DatF,"Dihedrals\n\n"); fprintf(DatF,"Dihedrals\n\n");
for(k=0; k < total_no_dihedrals; k++) for(k=0; k < total_no_dihedrals; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i\n",k+1,
dihedrals[k].type+1, dihedrals[k].type+1,
dihedrals[k].members[0]+1, dihedrals[k].members[0]+1,
dihedrals[k].members[1]+1, dihedrals[k].members[1]+1,
dihedrals[k].members[2]+1, dihedrals[k].members[2]+1,
dihedrals[k].members[3]+1); dihedrals[k].members[3]+1);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/***** OUT-OF-PLANES *****/ /***** OUT-OF-PLANES *****/
if (total_no_oops+total_no_angle_angles > 0) { if (total_no_oops+total_no_angle_angles > 0) {
fprintf(DatF,"Impropers\n\n"); fprintf(DatF,"Impropers\n\n");
for (k=0; k < total_no_oops; k++) for (k=0; k < total_no_oops; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n", k+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n", k+1,
oops[k].type+1, oops[k].type+1,
oops[k].members[0]+1, oops[k].members[0]+1,
oops[k].members[1]+1, oops[k].members[1]+1,
oops[k].members[2]+1, oops[k].members[2]+1,
oops[k].members[3]+1); oops[k].members[3]+1);
if (forcefield == 2) { if (forcefield == 2) {
for (k=0; k < total_no_angle_angles; k++) for (k=0; k < total_no_angle_angles; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n",k+total_no_oops+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n",k+total_no_oops+1,
angleangles[k].type+no_oop_types+1, angleangles[k].type+no_oop_types+1,
angleangles[k].members[0]+1, angleangles[k].members[0]+1,
angleangles[k].members[1]+1, angleangles[k].members[1]+1,
angleangles[k].members[2]+1, angleangles[k].members[2]+1,
angleangles[k].members[3]+1); angleangles[k].members[3]+1);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/* Close data file */ /* Close data file */
if (fclose(DatF) !=0) { if (fclose(DatF) !=0) {
fprintf(stderr,"Error closing %s.lammps01\n", rootname); fprintf(stderr,"Error closing %s.lammps01\n", rootname);
exit(1); exit(1);
} }
} }

View File

@ -1,333 +1,333 @@
/* /*
* This function creates and writes the data file to be used with LAMMPS * This function creates and writes the data file to be used with LAMMPS
*/ */
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
#include "Forcefield.h" #include "Forcefield.h"
void WriteDataFile05(char *nameroot,int forcefield) void WriteDataFile05(char *nameroot,int forcefield)
{ {
int i,j,k,m; int i,j,k,m;
char line[MAX_LINE_LENGTH]; char line[MAX_LINE_LENGTH];
FILE *DatF; FILE *DatF;
/* Open data file */ /* Open data file */
sprintf(line,"%s.lammps05",rootname); sprintf(line,"%s.lammps05",rootname);
if (pflag > 0) fprintf(stderr," Writing LAMMPS 2005 data file: %s\n",line); if (pflag > 0) fprintf(stderr," Writing LAMMPS 2005 data file: %s\n",line);
if( (DatF = fopen(line,"w")) == NULL ) { if( (DatF = fopen(line,"w")) == NULL ) {
fprintf(stderr,"Cannot open %s\n",line); fprintf(stderr,"Cannot open %s\n",line);
exit(2); exit(2);
} }
if (forcefield == 1) total_no_angle_angles = 0; if (forcefield == 1) total_no_angle_angles = 0;
fprintf(DatF, "LAMMPS 2005 data file for %s\n\n", nameroot); fprintf(DatF, "LAMMPS 2005 data file for %s\n\n", nameroot);
fprintf(DatF, " %6d atoms\n", total_no_atoms); fprintf(DatF, " %6d atoms\n", total_no_atoms);
fprintf(DatF, " %6d bonds\n", total_no_bonds); fprintf(DatF, " %6d bonds\n", total_no_bonds);
fprintf(DatF, " %6d angles\n",total_no_angles); fprintf(DatF, " %6d angles\n",total_no_angles);
fprintf(DatF, " %6d dihedrals\n", total_no_dihedrals); fprintf(DatF, " %6d dihedrals\n", total_no_dihedrals);
fprintf(DatF, " %6d impropers\n", total_no_oops+total_no_angle_angles); fprintf(DatF, " %6d impropers\n", total_no_oops+total_no_angle_angles);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF, " %3d atom types\n", no_atom_types); fprintf(DatF, " %3d atom types\n", no_atom_types);
if (no_bond_types > 0) if (no_bond_types > 0)
fprintf(DatF, " %3d bond types\n", no_bond_types); fprintf(DatF, " %3d bond types\n", no_bond_types);
if (no_angle_types> 0) if (no_angle_types> 0)
fprintf(DatF, " %3d angle types\n", no_angle_types); fprintf(DatF, " %3d angle types\n", no_angle_types);
if (no_dihedral_types > 0) fprintf (DatF," %3d dihedral types\n", if (no_dihedral_types > 0) fprintf (DatF," %3d dihedral types\n",
no_dihedral_types); no_dihedral_types);
if (forcefield > 1) { if (forcefield > 1) {
if ((no_oop_types + no_angleangle_types) > 0) if ((no_oop_types + no_angleangle_types) > 0)
fprintf (DatF, " %3d improper types\n", fprintf (DatF, " %3d improper types\n",
no_oop_types + no_angleangle_types); no_oop_types + no_angleangle_types);
} }
else { else {
if (no_oop_types > 0) if (no_oop_types > 0)
fprintf (DatF, " %3d improper types\n", no_oop_types); fprintf (DatF, " %3d improper types\n", no_oop_types);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF, " %15.9f %15.9f xlo xhi\n", pbc[0], pbc[3]); fprintf(DatF, " %15.9f %15.9f xlo xhi\n", pbc[0], pbc[3]);
fprintf(DatF, " %15.9f %15.9f ylo yhi\n", pbc[1], pbc[4]); fprintf(DatF, " %15.9f %15.9f ylo yhi\n", pbc[1], pbc[4]);
fprintf(DatF, " %15.9f %15.9f zlo zhi\n", pbc[2], pbc[5]); fprintf(DatF, " %15.9f %15.9f zlo zhi\n", pbc[2], pbc[5]);
/* MASSES */ /* MASSES */
fprintf(DatF, "\nMasses\n\n"); fprintf(DatF, "\nMasses\n\n");
for(k=0; k < no_atom_types; k++) for(k=0; k < no_atom_types; k++)
fprintf(DatF, " %3d %10.6f\n",k+1,atomtypes[k].mass); fprintf(DatF, " %3d %10.6f\n",k+1,atomtypes[k].mass);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
/* COEFFICIENTS */ /* COEFFICIENTS */
fprintf(DatF,"Pair Coeffs\n\n"); fprintf(DatF,"Pair Coeffs\n\n");
for (i=0; i < no_atom_types; i++) { for (i=0; i < no_atom_types; i++) {
fprintf(DatF, " %3i ", i+1); fprintf(DatF, " %3i ", i+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%14.10f ", atomtypes[i].params[j]); fprintf(DatF, "%14.10f ", atomtypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
if (no_bond_types > 0) { if (no_bond_types > 0) {
if (forcefield == 1) m = 2; if (forcefield == 1) m = 2;
if (forcefield == 2) m = 4; if (forcefield == 2) m = 4;
fprintf(DatF,"Bond Coeffs\n\n"); fprintf(DatF,"Bond Coeffs\n\n");
for (i=0; i < no_bond_types; i++) { for (i=0; i < no_bond_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", bondtypes[i].params[j]); fprintf(DatF, "%10.4f ", bondtypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_angle_types > 0) { if (no_angle_types > 0) {
if (forcefield == 1) m = 2; if (forcefield == 1) m = 2;
if (forcefield == 2) m = 4; if (forcefield == 2) m = 4;
fprintf(DatF,"Angle Coeffs\n\n"); fprintf(DatF,"Angle Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", angletypes[i].params[j]); fprintf(DatF, "%10.4f ", angletypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_dihedral_types > 0) { if (no_dihedral_types > 0) {
if (forcefield == 1) m = 3; if (forcefield == 1) m = 3;
if (forcefield == 2) m = 6; if (forcefield == 2) m = 6;
fprintf(DatF,"Dihedral Coeffs\n\n"); fprintf(DatF,"Dihedral Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < m; j++) for ( j = 0; j < m; j++)
fprintf(DatF, "%10.4f ", dihedraltypes[i].params[j]); fprintf(DatF, "%10.4f ", dihedraltypes[i].params[j]);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (forcefield == 1) { if (forcefield == 1) {
if (no_oop_types > 0) { if (no_oop_types > 0) {
fprintf(DatF,"Improper Coeffs\n\n"); fprintf(DatF,"Improper Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
else if (forcefield == 2) { else if (forcefield == 2) {
if ((no_oop_types + no_angleangle_types) > 0) { if ((no_oop_types + no_angleangle_types) > 0) {
fprintf(DatF,"Improper Coeffs\n\n"); fprintf(DatF,"Improper Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
for (i=0; i < no_angleangle_types; i++) { for (i=0; i < no_angleangle_types; i++) {
fprintf(DatF, "%3i ", i+no_oop_types+1); fprintf(DatF, "%3i ", i+no_oop_types+1);
for ( j = 0; j < 2; j++) for ( j = 0; j < 2; j++)
fprintf(DatF, "%10.4f ", 0.0); fprintf(DatF, "%10.4f ", 0.0);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
if (forcefield == 2) { if (forcefield == 2) {
if (no_angle_types > 0) { if (no_angle_types > 0) {
fprintf(DatF,"BondBond Coeffs\n\n"); fprintf(DatF,"BondBond Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", angletypes[i].bondbond_cross_term[j]); fprintf(DatF, "%10.4f ", angletypes[i].bondbond_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"BondAngle Coeffs\n\n"); fprintf(DatF,"BondAngle Coeffs\n\n");
for (i=0; i < no_angle_types; i++) { for (i=0; i < no_angle_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 4; j++) for ( j = 0; j < 4; j++)
fprintf(DatF, "%10.4f ",angletypes[i].bondangle_cross_term[j]); fprintf(DatF, "%10.4f ",angletypes[i].bondangle_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if ((no_oop_types+no_angleangle_types) > 0) { if ((no_oop_types+no_angleangle_types) > 0) {
fprintf(DatF,"AngleAngle Coeffs\n\n"); fprintf(DatF,"AngleAngle Coeffs\n\n");
for (i=0; i < no_oop_types; i++) { for (i=0; i < no_oop_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 6; j++) for ( j = 0; j < 6; j++)
fprintf(DatF, "%10.4f ", ooptypes[i].angleangle_params[j]); fprintf(DatF, "%10.4f ", ooptypes[i].angleangle_params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
for (i=0; i < no_angleangle_types; i++) { for (i=0; i < no_angleangle_types; i++) {
fprintf(DatF, "%3i ", i+no_oop_types+1); fprintf(DatF, "%3i ", i+no_oop_types+1);
for ( j = 0; j < 6; j++) for ( j = 0; j < 6; j++)
fprintf(DatF, "%10.4f ", angleangletypes[i].params[j]); fprintf(DatF, "%10.4f ", angleangletypes[i].params[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
if (no_dihedral_types > 0) { if (no_dihedral_types > 0) {
fprintf(DatF,"AngleAngleTorsion Coeffs\n\n"); fprintf(DatF,"AngleAngleTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF,"%10.4f ", fprintf(DatF,"%10.4f ",
dihedraltypes[i].angleangledihedral_cross_term[j]); dihedraltypes[i].angleangledihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"EndBondTorsion Coeffs\n\n"); fprintf(DatF,"EndBondTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%i ", i+1); fprintf(DatF, "%i ", i+1);
for ( j = 0; j < 8; j++) for ( j = 0; j < 8; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].endbonddihedral_cross_term[j]); dihedraltypes[i].endbonddihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"MiddleBondTorsion Coeffs\n\n"); fprintf(DatF,"MiddleBondTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 4; j++) for ( j = 0; j < 4; j++)
fprintf(DatF,"%10.4f ", fprintf(DatF,"%10.4f ",
dihedraltypes[i].midbonddihedral_cross_term[j]); dihedraltypes[i].midbonddihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"BondBond13 Coeffs\n\n"); fprintf(DatF,"BondBond13 Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 3; j++) for ( j = 0; j < 3; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].bond13_cross_term[j]); dihedraltypes[i].bond13_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
fprintf(DatF,"AngleTorsion Coeffs\n\n"); fprintf(DatF,"AngleTorsion Coeffs\n\n");
for (i=0; i < no_dihedral_types; i++) { for (i=0; i < no_dihedral_types; i++) {
fprintf(DatF, "%3i ", i+1); fprintf(DatF, "%3i ", i+1);
for ( j = 0; j < 8; j++) for ( j = 0; j < 8; j++)
fprintf(DatF, "%10.4f ", fprintf(DatF, "%10.4f ",
dihedraltypes[i].angledihedral_cross_term[j]); dihedraltypes[i].angledihedral_cross_term[j]);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* ATOMS */ /* ATOMS */
fprintf(DatF, "Atoms\n\n"); fprintf(DatF, "Atoms\n\n");
for(k=0; k < total_no_atoms; k++) { for(k=0; k < total_no_atoms; k++) {
fprintf(DatF, " %6i %6i %3i %9.6f %15.9f %15.9f %15.9f\n", fprintf(DatF, " %6i %6i %3i %9.6f %15.9f %15.9f %15.9f\n",
k+1, k+1,
atoms[k].molecule, atoms[k].molecule,
atoms[k].type+1, atoms[k].type+1,
atoms[k].q, atoms[k].q,
atoms[k].x[0], atoms[k].x[0],
atoms[k].x[1], atoms[k].x[1],
atoms[k].x[2]); atoms[k].x[2]);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
/***** BONDS *****/ /***** BONDS *****/
if (total_no_bonds > 0) { if (total_no_bonds > 0) {
fprintf(DatF, "Bonds\n\n"); fprintf(DatF, "Bonds\n\n");
for(k=0; k < total_no_bonds; k++) for(k=0; k < total_no_bonds; k++)
fprintf(DatF, "%6i %3i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i\n",k+1,
bonds[k].type+1, bonds[k].type+1,
bonds[k].members[0]+1, bonds[k].members[0]+1,
bonds[k].members[1]+1); bonds[k].members[1]+1);
fprintf(DatF,"\n"); fprintf(DatF,"\n");
} }
/***** ANGLES *****/ /***** ANGLES *****/
if (total_no_angles > 0) { if (total_no_angles > 0) {
fprintf(DatF, "Angles\n\n"); fprintf(DatF, "Angles\n\n");
for(k=0; k < total_no_angles; k++) for(k=0; k < total_no_angles; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i %6i\n",k+1,
angles[k].type+1, angles[k].type+1,
angles[k].members[0]+1, angles[k].members[0]+1,
angles[k].members[1]+1, angles[k].members[1]+1,
angles[k].members[2]+1); angles[k].members[2]+1);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/***** TORSIONS *****/ /***** TORSIONS *****/
if (total_no_dihedrals > 0) { if (total_no_dihedrals > 0) {
fprintf(DatF,"Dihedrals\n\n"); fprintf(DatF,"Dihedrals\n\n");
for(k=0; k < total_no_dihedrals; k++) for(k=0; k < total_no_dihedrals; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i\n",k+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i\n",k+1,
dihedrals[k].type+1, dihedrals[k].type+1,
dihedrals[k].members[0]+1, dihedrals[k].members[0]+1,
dihedrals[k].members[1]+1, dihedrals[k].members[1]+1,
dihedrals[k].members[2]+1, dihedrals[k].members[2]+1,
dihedrals[k].members[3]+1); dihedrals[k].members[3]+1);
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/***** OUT-OF-PLANES *****/ /***** OUT-OF-PLANES *****/
if (total_no_oops+total_no_angle_angles > 0) { if (total_no_oops+total_no_angle_angles > 0) {
fprintf(DatF,"Impropers\n\n"); fprintf(DatF,"Impropers\n\n");
for (k=0; k < total_no_oops; k++) for (k=0; k < total_no_oops; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n", k+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n", k+1,
oops[k].type+1, oops[k].type+1,
oops[k].members[0]+1, oops[k].members[0]+1,
oops[k].members[1]+1, oops[k].members[1]+1,
oops[k].members[2]+1, oops[k].members[2]+1,
oops[k].members[3]+1); oops[k].members[3]+1);
if (forcefield == 2) { if (forcefield == 2) {
for (k=0; k < total_no_angle_angles; k++) for (k=0; k < total_no_angle_angles; k++)
fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n",k+total_no_oops+1, fprintf(DatF, "%6i %3i %6i %6i %6i %6i \n",k+total_no_oops+1,
angleangles[k].type+no_oop_types+1, angleangles[k].type+no_oop_types+1,
angleangles[k].members[0]+1, angleangles[k].members[0]+1,
angleangles[k].members[1]+1, angleangles[k].members[1]+1,
angleangles[k].members[2]+1, angleangles[k].members[2]+1,
angleangles[k].members[3]+1); angleangles[k].members[3]+1);
} }
fprintf(DatF, "\n"); fprintf(DatF, "\n");
} }
/* Close data file */ /* Close data file */
if (fclose(DatF) !=0) { if (fclose(DatF) !=0) {
fprintf(stderr,"Error closing %s.lammps05\n", rootname); fprintf(stderr,"Error closing %s.lammps05\n", rootname);
exit(1); exit(1);
} }
} }

View File

@ -1,275 +1,275 @@
/* /*
* *
* msi2lmp.exe V3.6 * msi2lmp.exe V3.6
* *
* v3.6 KLA - Changes to output to either lammps 2001 (F90 version) or to * v3.6 KLA - Changes to output to either lammps 2001 (F90 version) or to
* lammps 2005 (C++ version) * lammps 2005 (C++ version)
* *
* v3.4 JEC - a number of minor changes due to way newline and EOF are generated * v3.4 JEC - a number of minor changes due to way newline and EOF are generated
* on Materials Studio generated .car and .mdf files as well as odd * on Materials Studio generated .car and .mdf files as well as odd
* behavior out of newer Linux IO libraries. ReadMdfFile was restructured * behavior out of newer Linux IO libraries. ReadMdfFile was restructured
* in the process. * in the process.
* *
* v3.1 JEC - changed IO interface to standard in/out, forcefield file * v3.1 JEC - changed IO interface to standard in/out, forcefield file
* location can be indicated by environmental variable; added * location can be indicated by environmental variable; added
* printing options, consistency checks and forcefield * printing options, consistency checks and forcefield
* parameter versions sensitivity (highest one used) * parameter versions sensitivity (highest one used)
* *
* v3.0 JEC - program substantially rewritten to reduce execution time * v3.0 JEC - program substantially rewritten to reduce execution time
* and be 98 % dynamic in memory use (still fixed limits on * and be 98 % dynamic in memory use (still fixed limits on
* number of parameter types for different internal coordinate * number of parameter types for different internal coordinate
* sets) * sets)
* *
* v2.0 MDP - got internal coordinate information from mdf file and * v2.0 MDP - got internal coordinate information from mdf file and
* forcefield parameters from frc file thus eliminating * forcefield parameters from frc file thus eliminating
* need for Discover * need for Discover
* *
* V1.0 SL - original version. Used .car file and internal coordinate * V1.0 SL - original version. Used .car file and internal coordinate
* information from Discover to produce LAMMPS data file. * information from Discover to produce LAMMPS data file.
* *
* This program uses the .car and .mdf files from MSI/Biosyms's INSIGHT * This program uses the .car and .mdf files from MSI/Biosyms's INSIGHT
* program to produce a LAMMPS data file. * program to produce a LAMMPS data file.
* *
* The program is started by supplying information at the command prompt * The program is started by supplying information at the command prompt
* according to the usage described below. * according to the usage described below.
* *
* USAGE: msi2lmp3 ROOTNAME {-print #} {-class #} {-frc FRC_FILE} -2001 * USAGE: msi2lmp3 ROOTNAME {-print #} {-class #} {-frc FRC_FILE} -2001
* *
* -- msi2lmp3 is the name of the executable * -- msi2lmp3 is the name of the executable
* -- ROOTNAME is the base name of the .car and .mdf files * -- ROOTNAME is the base name of the .car and .mdf files
* *
* -- -print * -- -print
* # is the print level: 0 - silent except for errors * # is the print level: 0 - silent except for errors
* 1 - minimal (default) * 1 - minimal (default)
* 2 - more verbose * 2 - more verbose
* -- -class * -- -class
* # is the class of forcefield to use (I = Class I e.g., CVFF) * # is the class of forcefield to use (I = Class I e.g., CVFF)
* (II = Class II e.g., CFFx ) * (II = Class II e.g., CFFx )
* default is -class I * default is -class I
* *
* -- -frc - specifies name of the forcefield file (e.g., cff91) * -- -frc - specifies name of the forcefield file (e.g., cff91)
* *
* If the name includes a hard wired directory (i.e., if the name * If the name includes a hard wired directory (i.e., if the name
* starts with . or /), then the name is used alone. Otherwise, * starts with . or /), then the name is used alone. Otherwise,
* the program looks for the forcefield file in $BIOSYM_LIBRARY. * the program looks for the forcefield file in $BIOSYM_LIBRARY.
* If $BIOSYM_LIBRARY is not set, then the current directory is * If $BIOSYM_LIBRARY is not set, then the current directory is
* used. * used.
* *
* If the file name does not include a dot after the first * If the file name does not include a dot after the first
* character, then .frc is appended to the name. * character, then .frc is appended to the name.
* *
* For example, -frc cvff (assumes cvff.frc is in $BIOSYM_LIBRARY * For example, -frc cvff (assumes cvff.frc is in $BIOSYM_LIBRARY
* or .) * or .)
* *
* -frc cff/cff91 (assumes cff91.frc is in * -frc cff/cff91 (assumes cff91.frc is in
* $BIOSYM_LIBRARY/cff or ./cff) * $BIOSYM_LIBRARY/cff or ./cff)
* *
* -frc /usr/local/biosym/forcefields/cff95 (absolute * -frc /usr/local/biosym/forcefields/cff95 (absolute
* location) * location)
* *
* By default, the program uses $BIOSYM_LIBRARY/cvff.frc * By default, the program uses $BIOSYM_LIBRARY/cvff.frc
* *
* -- -2001 will output a data file for the FORTRAN 90 version of LAMMPS (2001) * -- -2001 will output a data file for the FORTRAN 90 version of LAMMPS (2001)
* By default, the program will output for the C++ version of LAMMPS. * By default, the program will output for the C++ version of LAMMPS.
* *
* -- output is written to a file called ROOTNAME.lammps{01/05} * -- output is written to a file called ROOTNAME.lammps{01/05}
* *
* *
**************************************************************** ****************************************************************
* *
* Msi2lmp3 * Msi2lmp3
* *
* This is the third version of a program that generates a LAMMPS * This is the third version of a program that generates a LAMMPS
* data file based on the information in a MSI car file (atom * data file based on the information in a MSI car file (atom
* coordinates) and mdf file (molecular topology). A key part of * coordinates) and mdf file (molecular topology). A key part of
* the program looks up forcefield parameters from an MSI frc file. * the program looks up forcefield parameters from an MSI frc file.
* *
* The first version was written by Steve Lustig at Dupont, but * The first version was written by Steve Lustig at Dupont, but
* required using Discover to derive internal coordinates and * required using Discover to derive internal coordinates and
* forcefield parameters * forcefield parameters
* *
* The second version was written by Michael Peachey while an * The second version was written by Michael Peachey while an
* in intern in the Cray Chemistry Applications Group managed * in intern in the Cray Chemistry Applications Group managed
* by John Carpenter. This version derived internal coordinates * by John Carpenter. This version derived internal coordinates
* from the mdf file and looked up parameters in the frc file * from the mdf file and looked up parameters in the frc file
* thus eliminating the need for Discover. * thus eliminating the need for Discover.
* *
* The third version was written by John Carpenter to optimize * The third version was written by John Carpenter to optimize
* the performance of the program for large molecular systems * the performance of the program for large molecular systems
* (the original code for deriving atom numbers was quadratic in time) * (the original code for deriving atom numbers was quadratic in time)
* and to make the program fully dynamic. The second version used * and to make the program fully dynamic. The second version used
* fixed dimension arrays for the internal coordinates. * fixed dimension arrays for the internal coordinates.
* *
* John Carpenter can be contacted by sending email to * John Carpenter can be contacted by sending email to
* jec374@earthlink.net * jec374@earthlink.net
* *
* November 2000 * November 2000
*/ */
#define MAIN #define MAIN
#include "Msi2LMP2.h" #include "Msi2LMP2.h"
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
int n,i,found_dot; /* Counter */ int n,i,found_dot; /* Counter */
int outv; int outv;
char *string; char *string;
char *frc_dir_name; char *frc_dir_name;
char *frc_file_name; char *frc_file_name;
FILE *DatF; FILE *DatF;
/* Functions called from within main */ /* Functions called from within main */
/* All code is located in .c file with function name */ /* All code is located in .c file with function name */
extern void FrcMenu(); extern void FrcMenu();
extern void ReadCarFile(); extern void ReadCarFile();
extern void ReadMdfFile(); extern void ReadMdfFile();
extern void ReadFrcFile(); extern void ReadFrcFile();
extern void MakeLists(); extern void MakeLists();
extern void GetParameters(int); extern void GetParameters(int);
extern void CheckLists(); extern void CheckLists();
extern void WriteDataFile(FILE *,char *,int); extern void WriteDataFile(FILE *,char *,int);
outv = 2005; outv = 2005;
pflag = 1; pflag = 1;
forcefield = 1; /* Variable that identifies forcefield to use */ forcefield = 1; /* Variable that identifies forcefield to use */
frc_file_name = (char *) calloc(160,sizeof(char)); frc_file_name = (char *) calloc(160,sizeof(char));
frc_dir_name = (char *) calloc(160,sizeof(char)); frc_dir_name = (char *) calloc(160,sizeof(char));
frc_dir_name = getenv("BIOSYM_LIBRARY"); frc_dir_name = getenv("BIOSYM_LIBRARY");
if (frc_dir_name == NULL) { if (frc_dir_name == NULL) {
frc_file_name = strcpy(frc_file_name,"./cvff.frc"); frc_file_name = strcpy(frc_file_name,"./cvff.frc");
} }
else { else {
for (i=0; i < strlen(frc_dir_name); i++) for (i=0; i < strlen(frc_dir_name); i++)
frc_file_name[i] = frc_dir_name[i]; frc_file_name[i] = frc_dir_name[i];
frc_file_name = strcat(frc_file_name,"/cvff.frc"); frc_file_name = strcat(frc_file_name,"/cvff.frc");
} }
if (argc < 2) { /* If no rootname was supplied, prompt for it */ if (argc < 2) { /* If no rootname was supplied, prompt for it */
fprintf(stderr,"The rootname of the .car and .mdf files must be entered\n"); fprintf(stderr,"The rootname of the .car and .mdf files must be entered\n");
} }
else /* rootname was supplied as first argument, copy to rootname */ else /* rootname was supplied as first argument, copy to rootname */
sprintf(rootname,"%s",argv[1]); sprintf(rootname,"%s",argv[1]);
n = 2; n = 2;
while (n < argc) { while (n < argc) {
if (strcmp(argv[n],"-class") == 0) { if (strcmp(argv[n],"-class") == 0) {
if (strcmp(argv[n+1],"I") == 0) { if (strcmp(argv[n+1],"I") == 0) {
forcefield = 1; forcefield = 1;
n++; n++;
} }
else if (strcmp(argv[n+1],"II") == 0) { else if (strcmp(argv[n+1],"II") == 0) {
forcefield = 2; forcefield = 2;
n++; n++;
} }
else { else {
fprintf(stderr,"Unrecognized Forcefield class: %s\n", fprintf(stderr,"Unrecognized Forcefield class: %s\n",
argv[n+1]); argv[n+1]);
n++; n++;
} }
} }
else if (strcmp(argv[n],"-2001") == 0) { else if (strcmp(argv[n],"-2001") == 0) {
outv = 2001; outv = 2001;
n++; n++;
} }
else if (strcmp(argv[n],"-frc") == 0) { else if (strcmp(argv[n],"-frc") == 0) {
if ((frc_dir_name != NULL) && (argv[n+1][0] != '.')) { if ((frc_dir_name != NULL) && (argv[n+1][0] != '.')) {
for (i=0; i < strlen(frc_dir_name); i++) { for (i=0; i < strlen(frc_dir_name); i++) {
frc_file_name[i] = frc_dir_name[i]; frc_file_name[i] = frc_dir_name[i];
} }
frc_file_name[strlen(frc_dir_name)] = '\0'; frc_file_name[strlen(frc_dir_name)] = '\0';
frc_file_name = strcat(frc_file_name,"/"); frc_file_name = strcat(frc_file_name,"/");
frc_file_name = strcat(frc_file_name,argv[n+1]); frc_file_name = strcat(frc_file_name,argv[n+1]);
} }
else { else {
frc_file_name = strcpy(frc_file_name,argv[n+1]); frc_file_name = strcpy(frc_file_name,argv[n+1]);
} }
found_dot = 0; found_dot = 0;
for (i=1; i < strlen(frc_file_name); i++) { for (i=1; i < strlen(frc_file_name); i++) {
if (frc_file_name[i] == '.') found_dot = 1; if (frc_file_name[i] == '.') found_dot = 1;
} }
if (found_dot == 0) if (found_dot == 0)
frc_file_name = strcat(frc_file_name,".frc"); frc_file_name = strcat(frc_file_name,".frc");
n++; n++;
} }
else if (strstr(argv[n],"-p") != NULL) { else if (strstr(argv[n],"-p") != NULL) {
pflag = atoi(argv[n+1]); pflag = atoi(argv[n+1]);
n++; n++;
} }
else { else {
fprintf(stderr,"Unrecognized option: %s\n",argv[n]); fprintf(stderr,"Unrecognized option: %s\n",argv[n]);
} }
n++; n++;
} }
for (i=0; i < strlen(frc_file_name); i++) for (i=0; i < strlen(frc_file_name); i++)
FrcFileName[i] = frc_file_name[i]; FrcFileName[i] = frc_file_name[i];
free(frc_file_name); free(frc_file_name);
if (pflag > 0) { if (pflag > 0) {
fprintf(stderr,"\nRunning Msi2lmp.....\n\n"); fprintf(stderr,"\nRunning Msi2lmp.....\n\n");
fprintf(stderr," Forcefield file name: %s\n",FrcFileName); fprintf(stderr," Forcefield file name: %s\n",FrcFileName);
fprintf(stderr," Forcefield class: %d\n\n",forcefield); fprintf(stderr," Forcefield class: %d\n\n",forcefield);
} }
if (((forcefield == 1) && (strstr(FrcFileName,"cff") != NULL) || if (((forcefield == 1) && (strstr(FrcFileName,"cff") != NULL) ||
(forcefield == 2) && (strstr(FrcFileName,"cvff") != NULL))) { (forcefield == 2) && (strstr(FrcFileName,"cvff") != NULL))) {
fprintf(stderr," WARNING - forcefield name and class appear to\n"); fprintf(stderr," WARNING - forcefield name and class appear to\n");
fprintf(stderr," be inconsistent - Errors may result\n\n"); fprintf(stderr," be inconsistent - Errors may result\n\n");
} }
/* Read in .car file */ /* Read in .car file */
ReadCarFile(); ReadCarFile();
/*Read in .mdf file */ /*Read in .mdf file */
ReadMdfFile(); ReadMdfFile();
/* Define bonds, angles, etc...*/ /* Define bonds, angles, etc...*/
if (pflag > 0) fprintf(stderr,"\n Building internal coordinate lists \n"); if (pflag > 0) fprintf(stderr,"\n Building internal coordinate lists \n");
MakeLists(); MakeLists();
/* Read .frc file into memory */ /* Read .frc file into memory */
if (pflag > 0) fprintf(stderr,"\n Reading forcefield file \n"); if (pflag > 0) fprintf(stderr,"\n Reading forcefield file \n");
ReadFrcFile(); ReadFrcFile();
/* Get forcefield parameters */ /* Get forcefield parameters */
if (pflag > 0) fprintf(stderr,"\n Get parameters for this molecular system\n"); if (pflag > 0) fprintf(stderr,"\n Get parameters for this molecular system\n");
GetParameters(forcefield); GetParameters(forcefield);
/* Do internal check of internal coordinate lists */ /* Do internal check of internal coordinate lists */
if (pflag > 0) fprintf(stderr,"\n Check parameters for internal consistency\n"); if (pflag > 0) fprintf(stderr,"\n Check parameters for internal consistency\n");
CheckLists(); CheckLists();
if (outv == 2001) { fprintf(stderr,"\n Writing LAMMPS 2001 data file\n"); if (outv == 2001) { fprintf(stderr,"\n Writing LAMMPS 2001 data file\n");
WriteDataFile01(rootname,forcefield); WriteDataFile01(rootname,forcefield);
} }
else if (outv == 2005) {fprintf(stderr,"\n Writing LAMMPS 2005 data file\n"); else if (outv == 2005) {fprintf(stderr,"\n Writing LAMMPS 2005 data file\n");
WriteDataFile05(rootname,forcefield); WriteDataFile05(rootname,forcefield);
} }
if (pflag > 0) fprintf(stderr,"\nNormal program termination\n"); if (pflag > 0) fprintf(stderr,"\nNormal program termination\n");
} }
#include <ctype.h> #include <ctype.h>
int blank_line(char *line) int blank_line(char *line)
{ {
int i,n; int i,n;
for (i=0,n=0; i < strlen(line); i++) { for (i=0,n=0; i < strlen(line); i++) {
if (isalnum((unsigned char)line[i])) n++; if (isalnum((unsigned char)line[i])) n++;
} }
if (n > 0) { if (n > 0) {
return(0); return(0);
} }
else { else {
return(1); return(1);
} }
} }